DATA Step, Macro, Functions and more

How to store existing datasets names into variables?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

How to store existing datasets names into variables?

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.


Accepted Solutions
Solution
‎01-23-2018 04:15 PM
Super User
Posts: 24,026

Re: How to store existing datasets names into variables?

Posted in reply to danfavero

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


All Replies
Super User
Posts: 2,068

Re: How to store existing datasets names into variables?

Posted in reply to danfavero

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

Super User
Posts: 2,068

Re: How to store existing datasets names into variables?

Posted in reply to novinosrin
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;
Solution
‎01-23-2018 04:15 PM
Super User
Posts: 24,026

Re: How to store existing datasets names into variables?

Posted in reply to danfavero

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 136 views
  • 2 likes
  • 3 in conversation