Hi, I have 1000 datasets with 1 row in each dataset and they are named in a similar fashion like this.
seg_1 seg_2 seg_3..........seg_1000.
I'm trying to concatenate all these 1000 datasets in one data step.
%DO q = 1 %TO 1000;
SET seg_&q. ;
But I'm getting only 1 row in my final dataset (all_seg).
Can somebody pls help me wiht this.( I dont want to write all the 1000 datset names after the SET Statement).
Consider the following sample data and programs (without involving any SAS macro into the mix)
Which result do you hope to produce? The results from dataset TESTIT or the results from dataset NEWTEST?????
Remember that the SAS Macro facility is not EXECUTING any code for you. It is just doing the typing so your macro program is typing the program code that you want to have sent to the compiler -- when the macro program has finished typing for you.
What is the correct SET statement for what you want to achieve?
proc print data=testit;
title '3 set statements';
set seg_1 seg_2 seg_3;
proc print data=newtest;
title '1 set statement';
If that's what you want, then your macro program is incorrect. You need the SET statement (the beginning of the statement) to be OUTSIDE the %DO loop and, you need the ending semicolon for the SET statement to be outside the DO loop.
So, that's the problem with your macro program.
However, the SET statement forces SAS to read each dataset, row, by row -- for 1000 datasets, depending on how big they are, this could take significant time to process. The PROC APPEND method may prove to be for efficient for processing, because the datasets are not read, row by row to construct the new dataset.
You might want to consider the PROC APPEND approach, unless there was other processing you were going to do in the DATA step program.