BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have 200 datasets:d1,d2,d3...d200, each with only one observation, I want to stack them into one dataset, I tried the codes below but it didn't work:

data final;
set d1-d200;
run;

I appreciate your advice in having it work out.

Thanks!
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You must list each file separately on the SET statement. A utility SAS macro to generate the SET parameters can look something like:

%MACRO GENSET(FILEPFX=, LOW=, HIGH=);
%DO CYC=&LOW %TO &HIGH;
&FILEPFX&CYC
%END;
%MEND GENSET;

DATA FINAL;
SET %GENSET(FILEPFX=D,LOW=1,HIGH=200);
RUN;

Scott Barry
SBBWorks, Inc.


SAS Macro Language: Reference
Introduction to the Macro Facility
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293969.htm

SAS Macro Programming for Beginners
Susan J. Slaughter, Avocet Solutions, Davis, CA
Lora D. Delwiche, Delwiche Consulting, Winters, CA
http://www2.sas.com/proceedings/sugi29/243-29.pdf
deleted_user
Not applicable
It works! Thank you very much Scott.
Doc_Duke
Rhodochrosite | Level 12
Beickham,

Just an FYI. While Scott's solution works for 200 datasets and your immediate problem is solved, it does not scale to 2000, say. If requires that all of the datasets be open at once and the operating system generally limits the number of "file handles" available (varies by OS).

You could re-write the macro to handle an arbitrary number of datasets, but it could take a lot longer to run.

Doc Muhlbaier
Duke
deleted_user
Not applicable
I recently came across the parameter OPEN=DEFER for the SET statement, which might get around the problem of too many files open at once.
tsbrown
Calcite | Level 5

This technique tends to work quite well.

 


data final;
set d:;
run;

 

data output.combined;
set output.final_:;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 7317 views
  • 1 like
  • 4 in conversation