BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Quartz | Level 8

@Tom I decided to use a macro to see how it works. Referring to the different librefs below is my code.I am not sure if it fits in memory, but it would be worth trying.

%macro allfiles(varlist=);










data out_all;

set %allfiles(varlist=%str((keep=id var1 var2 type); 



Super User Tom
Super User

Macro code is not going to change the SAS code that is run or how SAS runs it. It just makes it easier for you type it.  For just 5 or 6 datasets if is just is probably easier to just use copy/paste to replicate the code rather than complicate your program with macro code.


Most SAS jobs are I/O bound and it sounds like that is your problem. Run PROC CONTENTS on your input datasets and check some things. Make sure they were made with the same operating system and version of SAS.  If SAS has to use CEDA to read the files it will slow it down a lot.  Check if they are already sorted by the ID variable(or at least if SAS thinks so).  Eliminating the need to sort is a hugh deal.  Check if they are using SAS compression.  Many SAS datasets can get 60-80 reduction in disk size just by using the COMPRESS=BINARY option when creating them.


Try using the SPDE engine to store your new subsets.  That can really reduce the disk space needed to store the data.


The main thing is subset as early as possible.   

If your list of ID values is small then store them in a macro variable.

proc sql noprint;
 select distinct id into :idlist separated by ' '
 from relation

%let varlist=id var1 vara varb varc ;
proc sort data=libname1.orig1(keep=&varlist) out=subset1 (compress=binary);
  by id;
  where id in (&idlist);
data combine/view=combine;
  set subset1 subset2 subset3 .... ;
  by id;

data final (compress=binary);
  merge relation combine ;
  by id;
Quartz | Level 8

@Tom Thanks for all your suggestions. I will definitely be implementing them. I have about 20000 ids so it will be hard to put them in a macro. It would have certainly helped to subset to those ids in the first step itself.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 17 replies
  • 4 in conversation