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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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