BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi there,

I was wondering if anyone knows how to create a macro variable for all the members in a library. I'm wanting to sort 30 datasets by a common variable and are considering using %do loop function, however would like to save time in typing the member names out in full.

Cheers
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Hi:
Several previous forum postings have discussed the use of DICTIONARY.TABLES and other types of DICTIONARY files in order to access information about SAS datasets. With PROC SQL, you can use the INTO clause in order to create macro variables from the results of a particular query. Some of the postings are:
http://support.sas.com/forums/thread.jspa?messageID=14535㣇
http://support.sas.com/forums/thread.jspa?messageID=9171⏓
http://support.sas.com/forums/thread.jspa?messageID=11252⯴

Here are some user group papers that outline what the "dictionary" tables do:
http://www2.sas.com/proceedings/sugi30/070-30.pdf
http://www2.sas.com/proceedings/sugi29/237-29.pdf
http://www.codecraftersinc.com/pdf/DictionaryTablesRefCard.pdf
http://www.lexjansen.com/pharmasug/2006/tutorials/tu03.pdf
http://www.qsl.net/kd6ttl/sas/sqlutilov.pdf

cynthia
deleted_user
Not applicable
Thanks for your prompt response Cynthia.
I've not used Proc SQL before. I'll try to work my way out through the threads you've provided.

Cheers
Cynthia_sas
SAS Super FREQ
Hi:
You can certainly use CALL SYMPUT and DATA step to create your macro variables from the SASHELP views of the DICTIONARY tables. I believe some of the papers referenced show both methods.

cynthia
deleted_user
Not applicable
I think this will work.

libname xx "c:\test";

data xx.a;
var1 = "testa";
run;

data xx.b;
var2 = "testb";
run;

proc sql noprint;
select memname into :dataset_names separated by ' '
from dictionary.tables
where lowcase(libname) = 'xx';
quit;

%put dataset_names = &dataset_names;


/* or you can use a data step */

data _null_;
set sashelp.vtable end=end;
where lowcase(libname) = 'xx';
length dataset_names $ 20;
retain dataset_names;
if _n_ = 1 then dataset_names = memname;
else dataset_names = strip(dataset_names) || ', ' || strip(memname) ;
if end then
do;
call symputx('dataset_names_2',dataset_names);
end;
run;

%put macro variable created by data step: &dataset_names_2;
Peter_C
Rhodochrosite | Level 12
call execute() in a data step might help[pre] data _null_ ;
set sashelp.vtable( where=( libname='YOURLIB' ));
call execute( 'proc sort data=yourlib.' !! memname );
call execute(' out= work.'!! memname ' );
call execute(' ; by BYVAR ; run; ' );
run ;[/pre]
I expect that solution is among those links Cynthia provided.

PeterC

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!

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
  • 5 replies
  • 778 views
  • 0 likes
  • 3 in conversation