@stataq wrote:
Hello,
How can I refer a macro variable and its value in a data step?
for example, if I have a dataset that have 3 variables A1 B2 and C3. If I set marco variable "%letr colvar=A1"., how can I utilized &colvar. to get a filter that macro variable colvar was setup as 'A1" and its value is within (1,2)?:
if &colvar.=A1 and &colvar. in (1,2) then do;...
how to refer a macro variable name, and how to refer a value that belong to a variable?
If I understand your question correctly, you simply code:
if symget('colvar'='A1') then if &colvar. in (1,2) then do;...
Note that all values of &colvar must exist as variables in the data set since there's code to test them, or SAS wil complain.
Otherwise a better method would be
%if &colvar.=A1 %then %do; if &colvar. in (1,2) then do;...end; %end;
Here, only the appropriate test is inserted in the data step.
... View more