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
Hi Cynthia ,
Yes I have created it
Thank you
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;
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.
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:
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
Thanks Cynthia for taking time to work through this
Thank you so much for all your help
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.