The SAS Output Delivery System and reporting techniques

multiple datasets into one sheet

Reply
Frequent Contributor
Posts: 120

multiple datasets into one sheet

Hi ,

I have 800 datasets and i want to export all the datasets into one sheet and not multiple sheet and each dataset has two varaibles

 

dataset A

count_id  rate

12          0.12

13         0.13

 

dataset B

count_id rate

15      0.11

16      0.22

 

i want both these datasets to write to one excel sheet

 

Can anyone pls help

 

Thanks

Respected Advisor
Posts: 3,124

Re: multiple datasets into one sheet

Am I the only one at work today Smiley Very Happy

 

Well you can two approaches,

1.  union/stack/append your sas tables first, if you don't like the intermedian table, you can opt for sas views, then output to Excel.

2. Do it on the fly, if you have SAS/ACCESS to pc files.

 

My gut tells me that you are asking for the #2, so here it goes:

 


LIBNAME OUT XLSX "/your output folder/want.XLSX";

DATA OUT.want;
SET table1 table2 .....;
RUN;


LIBNAME OUT CLEAR ;

 

If you have 800ish table, then you may want to leverage your meta data, meaning throwing the table names into a macro variable to avoid typing.

Respected Advisor
Posts: 4,659

Re: multiple datasets into one sheet

Two details to add to @Haikuo's suggestion

 

1) if your dataset names have a common prefix, you can use a dataset list in the set statement: SET TABLE: ;

2) If you want to remember which dataset the rows came from, you can add a third field to the data:

 

DATA OUT.want;
length from $32;
SET table: INDSNAME=DS;
from = scan(DS, 2, ".");
RUN;
PG
Ask a Question
Discussion stats
  • 2 replies
  • 200 views
  • 2 likes
  • 3 in conversation