Hi,
I am facing some issues with the following:
I have this code
%let num =5;
%let a&num = alpino;
I want that a&num resolves to a5 = alpino but I am not getting the expected result. Does anyone have an answer to solve this. Regards
@latristain wrote:
Hi,
I am facing some issues with the following:
I have this code
%let num =5;
%let a&num = alpino;
I want that a&num resolves to a5 = alpino but I am not getting the expected result. Does anyone have an answer to solve this. Regards
Not sure what you mean. Here is what you ran.
134 %let num =5; 135 136 %let a&num = alpino; 137 %put &=a5 ; A5=alpino
If you want the value to also include value of num then say that in the assignment statement.
138 %let num =5;
139
140 %let a&num = a&num = alpino;
141 %put &=a5 ;
A5=a5 = alpino
I suspect that what you did was something different than what you showed.
For example you might have generated NUM to include leading spaces.
146 data _null_; 147 call symput('num',5); 148 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 147:21 NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 149 %put NUM="&num"; NUM=" 5"
Which will cause trouble with your other %LET statement.
Make sure not to generate the spaces into the macro variable. For example by using the normal CALL SYMPUTX() function instead of the ancient CALL SYMPUT() function.
150 data _null_; 151 call symputX('num',5); 152 run; NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 153 %put NUM="&num"; NUM="5"
Or adding the TRIMMED keyword in PROC SQL code used to generate a macro variable.
This is an indirect reference. You can either use multiple ampersands or %SUPERQ to make this work.
%let num =5;
%let a&num = alpino;
%put NOTE: The variable names and values are &=num &=a5;
%PUT NOTE: The value retrieved with %NRSTR(%%SUPERQ%(A&NUM%)) is %superq(a&num);
%PUT NOTE: The value retrieved with %NRSTR(&&A&NUM) is &&a#
produces these notes in the log:
NOTE: The variable names and values are NUM=5 A5=alpino NOTE: The value retrieved with %SUPERQ(A&NUM) is alpino NOTE: The value retrieved with &&A&NUM is alpino
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.