I wrote a macro and not I want to run it for several variables. Some variables have the same prefix for example
var_name_d1
var_name_d2
var_name_d3
var_name_d4
var_name_d99
var_name_d999
I am not sure if they are in the same order in the dataset or if some other column may be in between these columns.
1- Can I write a short form to feed these 6 variables to my macro at one step?
2- If yes, how may I do that?
Thanks
Sounds like you need to either modify your macro or create a new one to call the old one.
So assume your macro calls to the old macro look like %old(dsn=sashelp.class,var=height) then your new code could look like this. (Note the macro wrapper is not really needed).
%macro new(prefix,dsname);
proc contents data=&dsn(keep=&prefix:) noprint out=names(keep=name); run;
data _null_;
set names ;
call execute(cats('%nrstr(%old)(dsn=',"&dsn",',var=',nliteral(name),')'));
run;
%mend;
Without seeing the macro you wrote, it's nearly impossible to give you advice. What does the macro do?
@Emma_at_SAS wrote:
Thank you, PaigeMiller. Based on the next suggestions, I noticed what you mean.
Thanks
Depending on what you are doing, the solution marked correct (from @Tom ) may be overkill. You may not need a loop or CALL EXECUTE at all, depending on what analysis you are doing with these variables.
No. The macro processor only deals with code, but the structures of datasets (and therefore the variables) become only evident when the code (created by the macro) later runs.
But you can build a macro variable from dictionary.columns that contains all the variable names and can be used as a macro parameter.
Sounds like you need to either modify your macro or create a new one to call the old one.
So assume your macro calls to the old macro look like %old(dsn=sashelp.class,var=height) then your new code could look like this. (Note the macro wrapper is not really needed).
%macro new(prefix,dsname);
proc contents data=&dsn(keep=&prefix:) noprint out=names(keep=name); run;
data _null_;
set names ;
call execute(cats('%nrstr(%old)(dsn=',"&dsn",',var=',nliteral(name),')'));
run;
%mend;
Thank you everyone!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.