Epoch
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 


Rechercher Advanced Search

Keywords

Latest topics
» SAS Macro: Convert numbers (e.g., 1000) to names (e.g., One thousand)
Automatically Separating Data into Excel Sheets EmptyMon Jun 10, 2013 2:57 pm by Admin

» SAS Enterprise Guide: Explore Data before you start Analysing
Automatically Separating Data into Excel Sheets EmptyMon Jun 10, 2013 2:53 pm by Admin

» Predictive Analytics
Automatically Separating Data into Excel Sheets EmptyFri May 31, 2013 3:30 pm by Admin

» Creating Frequency Report and Creating User Defined styles in SAS Add-In for Microsoft Office
Automatically Separating Data into Excel Sheets EmptyTue Oct 23, 2012 2:11 pm by pallav

» Prompted Reports in BI Dashboard
Automatically Separating Data into Excel Sheets EmptyThu Oct 11, 2012 4:54 pm by kushal

» Free SAS Webinar : Getting Started with SAS Hash Object
Automatically Separating Data into Excel Sheets EmptyWed Oct 10, 2012 6:08 pm by pallav

» Which SAS procedure changes the name of a permanent format for a variable stored in a SAS data set?
Automatically Separating Data into Excel Sheets EmptyTue Oct 02, 2012 12:47 am by rajin_kumar@yahoo.com

» What is written to SAS Log?
Automatically Separating Data into Excel Sheets EmptyTue Oct 02, 2012 12:39 am by rajin_kumar@yahoo.com

» SAS Portal and BI Dashboard: Customizing the Tabs
Automatically Separating Data into Excel Sheets EmptyTue Oct 02, 2012 12:33 am by kushal

Affiliates
free forum


Automatically Separating Data into Excel Sheets

Go down

Automatically Separating Data into Excel Sheets Empty Automatically Separating Data into Excel Sheets

Post  pallav Fri May 18, 2012 11:19 am

You can use the macro language with a PROC EXPORT to automatically generate a Excel workbook with one sheet for each level of a classification variable. In the following example we want to create a workbook (CLASS_AGES.XLS). We need to break up the data using AGE as a classification variable. Each age is to be shown on its own sheet in the workbook.

There are several ways to do this, however for this example we will create a series of macro variables; one for each level of the classification variable. This SQL step will create the macro variables &IDAGE1, &IDAG2, and so on up to 99 levels of AGE. The actual number of levels is stored in the automatic macro variable &SQLOBS.

proc sql noprint;
select distinct age
into :idage1 - :idage99
from sashelp.class;
%let agecnt = &sqlobs;
quit;



We then use a macro %DO loop to work through the list of AGE levels and create a PROC EXPORT for each, using a WHERE= data set option. Notice that the sheet name is changed for each of the values of the classification variable. &&IDAGE&I will resolve to the value of the variable AGE.

%do i = 1 %to &agecnt;
PROC EXPORT DATA = sashelp.class(where=(age=&&idage&i))
OUTFILE="C:\temp\class_ages.xls"
DBMS= excel
REPLACE;
sheet = "Age_&&idage&i";
RUN;
%END;


The full macro becomes:

%macro multisheet;
proc sql noprint;
select distinct age
into :idage1 - :idage99
from sashelp.class;
%let agecnt = &sqlobs;
quit;

%do i = 1 %to &agecnt;
PROC EXPORT DATA = sashelp.class(where=(age=&&idage&i))
OUTFILE="C:\temp\class_ages.xls"
DBMS= excel
REPLACE;
sheet = "Age_&&idage&i";
RUN;
%END;
%mend multisheet;
%multisheet


So easy.....Smile

pallav

Posts : 98
Join date : 2012-03-14
Location : Ahmedabad

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum