DATA Step, Macro, Functions and more

Few Queries .

Frequent Contributor
Posts: 140

Few Queries .

1. What are Auto call Macro how to create them?
2. How to create Macro in Global symbol table within Macro parameter?
3. In a sas session i am having 5 libraries currently i have common dataset CITY (Dset name) i wnat to kill  this dataset from all the libraries at once.As in future the no of lib may increase and decrease ased on  that session.
4. Create a table from one library with all datasets with data.

Super User
Super User
Posts: 7,401

Re: Few Queries .


1)  They are macro you use all the time, stored in a specific directory, and then used via options sasautos= option, e.g.

libname myautos "c:\myautos";

options sasautos=(myautos);

Just means you don't need to explicitly %include the files.

2)  Not sure what you mean here, macros defined with %let, call symput etc. See the documentation on Scope:

3)  Call execute or macro loop:

data _null_;

     set sashelp.vlibnam (where=(substr(LIBNAME1,5)="MY_ID"));

     /* Note I have assumed all libraries will be prefixed with MY_ID, change to your scenario */

     call  execute('proc datasets library='||strip(libname)||' nolist; delete city; quit;');


4)  Please clarify what you mean, do you just want new_libname to be a copy?  Then:

libname NEW_DATA "...";

data _null_;

     set sashelp.vtable (where=(libname="OLD_DATA"));

     call execute('data NEW_DATA.'||strip(NAME)||'; set OLD_DATA.'||strip(NAME)||'; run;');


Super User
Posts: 6,936

Re: Few Queries .

1. SAS(R) 9.2 Macro Language: Reference

2. %global variablename;


data _null_;

do lib_name = 'lib1','lib2',....,'libn';

  call execute("proc delete data=" !! strip(lib_name) !! ".city;run;");



Alternatively, you could store your libnames in a dataset and iterate through that.


proc sql;

select * from dictionary.tables where libname='libname';


Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,500

Re: Few Queries .

One additional bit about autocall macros: the SAS filename has to match the name of the macro called and best is to only have the code for the macro plus comments in that file.

Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation