BookmarkSubscribeRSS Feed
latristain
Calcite | Level 5

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

2 REPLIES 2
Tom
Super User Tom
Super User

@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.

 

SASJedi
SAS Super FREQ

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

 

Check out my Jedi SAS Tricks for SAS Users

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 291 views
  • 4 likes
  • 3 in conversation