BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cynthia_sas
Diamond | Level 26
Hi:
I'm confused. Are you trying to use a MACRO %DO loop to concatenate 250 -macro- variables or 250 dataset variables???

Cynthia
jhh197
Pyrite | Level 9

 

xp1_crs , xp2_crs and xp3_crs are already getting resolved in the macro and now I am using these values to prepare a list

like 2|3|1 so the values 2 is the value of xp1_crs and value 3 is the value of macro variable xp2_crs and the value of 1 is the value of xp3_crs

 

i am trying to concatenate  macro variable values

 

 

Thank you

Cynthia_sas
Diamond | Level 26
But, did you originally create the macro variable values from data that was in a dataset?
jhh197
Pyrite | Level 9

 

Hi Cynthia ,

 

Yes I have created it

 

Thank you

Reeza
Super User
What Cynthia is trying to mention, is that this would drastically easier in a data set. In fact it's trivial.

XP = catx('|', of xp1-xp250);
jhh197
Pyrite | Level 9


I am so confused why below code doesn't work and y doesn't resolve to 2|3|1

 

%let xp1 = 2;

%let xp2 = 3;

%let xp3 = 1;

 

 %do i=1 %to 3;
   %if &i=1 %then %do;
 %let y = &&xp&i._crs;
      %end;
 %else %do;
      %let y =%sysfunc(catx(|,&y,&&xp&i._crs));
 %end;

%end;


 %put &y;

 

Astounding
PROC Star

Because this expression gets resolved twice:

 

&&xp&i._crs

 

After one resolution, it resolves ti:

 

&xp1_crs

 

There is no macro variable by that name.  Since you mean the macro variable &XP1 followed by the text _crs, you need to add a second dot:

 

&&xp&i.._crs

 

The first one disappears when resolving &i. on the first pass through the expression.  The second one vanishes when resolving &xp1. on the second pass through the expression.

Cynthia_sas
Diamond | Level 26

And, there's really no need for CATX...it's overkill in this situation. This approach would work just as well whether you have 3 macro variables or 300:

no_catx_needed.png

 

Just my .02 and my extra little bit is that it would be easier to build &y from the original data variables instead of making a bunch of macro variables separately that you need to get together.

 

Cynthia

jhh197
Pyrite | Level 9

Thanks Cynthia for taking time to work through this

 

 

 

Thank you so much for all your help

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 23 replies
  • 18788 views
  • 3 likes
  • 5 in conversation