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

I have macro which creates multiple datasets and not always the same datasets are created. How can I keep only existing datasets names into a SAS variable and SET all of them together?

 

For example:

 

Data A;

      A=1;

Run;

 

Data C;

      C=1;

Run;

 

/*Here we will have an error as the dataset B does not exist*/

 

DATA All_Data;

      Set a b c;

run;

  

/*My idea was storage all the existing datasets (A and C) and do something like this*/

DATA All_Data;

      Set &existing_datasets.;

run;

 

How do I read the existing datasets and store their names into a variable?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Or use a naming convention. Name all your temporary datasets with _CombinedA, _CombinedB etc

Then when you’re trying to combine the data you can use the wildcard : to set the data.

 

data want;

set _combined: ;

run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

query dictionary tables into maco var and call the macrovar in set statements- your safe bet

novinosrin
Tourmaline | Level 20
proc sql;
select memname into :dsnlist separated by ' '
from sashelp.vtable /*or dictionary.tables*/
where libname='YOUR_LIBNAME';/*your lib where the datasets are stored */
quit;

data want;
set &dsnlist;
run;
Reeza
Super User

Or use a naming convention. Name all your temporary datasets with _CombinedA, _CombinedB etc

Then when you’re trying to combine the data you can use the wildcard : to set the data.

 

data want;

set _combined: ;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 3 replies
  • 853 views
  • 2 likes
  • 3 in conversation