Hi,
I would be very grateful if someone could please help me with the following query. I have a macro variable that contains a string, but the expression contains variable names. In the example below, the macro variable contains an expression that refers to variables 'a' and 'b'. The dataset 'testdata' contains these variables. I would like to know how to set 'c' to be the numeric result of evaluating the macro variable 'test', so should equal 3.
%Let test = "a+b";
Data testdata;
a=1;
b=2;
c=???;
Run;
Many thanks,
Hoa
%Let test = a+b;
Data testdata;
a=1;
b=2;
c=&test.;
Run;
Remove quotes from the %let statement.
Replace ??? In datastep with &c.
At its basics consider macro variables as a Find/Replace algorithm. The result needs to be valid SAS code.
%Let test = a+b;
Data testdata;
a=1;
b=2;
c=&test.;
Run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.