08-22-2017 07:01 AM
I have a macro variable :-
%let data1= cars;
%let data2= air;
%let data3= demo;
and I am using these macro in a do loop:-
%do i %to 3
proc print data=test1.data&i;
But its not resolving to the desired variable. How to resolve this half macro half string macro variable.
08-22-2017 07:06 AM
So you want for &i = 1 that data set resolve to cars?
You current logic resolves only &I as per you code. You need to apply a & if you want to use a name as a reference to macro variable name, and for resolution: &data1.
Since this is a two step resolution you need to add additional & so the resolution takes place in the order you need.
08-22-2017 07:10 AM
For indirect macro variable references, you need to use a double ampersand:
%let data1= cars; %let data2= class; %let data3= heart; %macro loop; %do i = 1 %to 3; proc print data=sashelp.&&data&i; run; %end; %mend; %loop
Use the "little running man" icon to post code, as it will preserve formatting of the code (no additional linefeeds etc when copy/pasting to SAS)