BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HoaTruong
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
avinashns
Obsidian | Level 7
%Let test = a+b;

Data testdata;
	a=1;
	b=2;
	c=&test.;
Run;

View solution in original post

3 REPLIES 3
Reeza
Super User

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. 

avinashns
Obsidian | Level 7
%Let test = a+b;

Data testdata;
	a=1;
	b=2;
	c=&test.;
Run;
HoaTruong
Obsidian | Level 7
Thank you very much! I forgot I had the quotes in the macro expression - too much staring at code..! 😃

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2110 views
  • 1 like
  • 3 in conversation