Like this?
libname Z '/SAS/sas1/sas_sub1/all_datasets';
data WANT;
set Z.AA Z.BB Z.CC %sysfunc(ifc(exist(Z.DD),Z.DD,));
run;
Defining a SAS libref that points to the "SAS/sas1/sas_sub1/all_datasets" path could be an option. You can then simply refer to the datasets by their names using a libname. More info on the libname statement here.
Something like this:
* Define the libname (Note that this statement does not contain an equal sign);
libname my_libname "SAS/sas1/sas_sub1/all_datasets";
* Create a new dataset called 'all_sets' that stacks the 'AA', 'BB', and 'CC' SAS datasets;
data all_sets;
set my_libname.AA my_libname.BB my_libname.CC;
run;
You have to be more specific than "Join datasets from that folder". What kind of join?
The first thing would be to assign a LIBRARY to point to the folder location.
Your example path looks incomplete you should add the bits at the front so that the path starts at a disc or mount point point but generally something like:
libname mydata 'SAS/sas1/sas_sub1/all_datasets';
Check the LOG for messages. If you do not see a successfully assigned result then the path needs to be modified as mentions.
The append can be done with that procedure assuming you have similar variables.
Proc append base=mydata.Alldata
data=mydata.AA;
run;
Proc append base=mydata.Alldata
data=mydata.BB;
run;
Note how the libname is used to address the data sets.
Later to add other sets you just change the name of the set on the DATA= line to add it to the AllData set.
The first time Alldata does not exist so the procedure creates it using the contents of mydata.AA to determine the number and types of variables.
If the sets to do not have the same variables this won't work because append will only add matching variables.
%let mystr =AA BB CC;
data want;
set &mystr.;
run;
here is another way but you get all SAS datasets so beware
libname myin "SAS/sas1/sas_sub1/all_datasets";
proc sql ;
select
trim(libname) || '.' || memname into :dataset_vars separated by ' '
from dictionary.tables
where upcase(libname)="MYIN"
and upcase(memname) like '%'
;
quit;
data myin.want;
set &dataset_vars;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.