Hello everyone,
I am trying to solve this problem but I haven't been able to. Please help.
%let thisvar = BUS;
%let buslist = A B C D E;
%macro A;
%do k = 1 %to %sysfunc(countw(&buslist));
%let list = %scan(&bustlist, &k)
%let xlist = %sysfunc(cats(&list,1_,&thisvar));
** I don't know how to do this part ***
%end;
%mend;
%A;
What I would like to have in the end is:
A1_BUS B1_BUS C1_BUS D1_BUS E1_BUS into some macro variable (say %let BUS=);
Please help. Thank you!
Hello @tonoplast,
Usually, SAS functions such as CATS are not needed to concatenate text in macro language. You could simplify the %DO loop to
%do k = 1 %to %sysfunc(countw(&buslist));
%let finlist = &finlist %scan(&buslist, &k)1_&thisvar;
%end;
Edit: Further simplified as per @Astounding's reminder.
Looks like I figured it out. If there is an easier way / better way than this, please let me know (this probably needs re-work from the beginning). Thank you.
%let thisvar = BUS;
%let buslist = A B C D E;
%let finlist=;
%macro A;
%do k = 1 %to %sysfunc(countw(&buslist));
%let list = %scan(&bustlist, &k)
%let xlist = %sysfunc(cats(&list,1_,&thisvar));
%let finlist = %sysfunc(cats(&finlist. &xlist));
%end;
%mend;
%A;
%put &finlist;
Some typos in the original question! But tonoplasts code works exactly as it should.
%let thisvar = BUS;
%let buslist = A B C D E;
%let finlist=;
%macro A;
%do k = 1 %to %sysfunc(countw(&buslist));
%let list = %scan(&buslist, &k);
%let xlist = %sysfunc(cats(&list,1_,&thisvar));
%let finlist = %sysfunc(cats(&finlist. &xlist));
%end;
%mend;
%A;
%put &finlist;
Hello @tonoplast,
Usually, SAS functions such as CATS are not needed to concatenate text in macro language. You could simplify the %DO loop to
%do k = 1 %to %sysfunc(countw(&buslist));
%let finlist = &finlist %scan(&buslist, &k)1_&thisvar;
%end;
Edit: Further simplified as per @Astounding's reminder.
Oh yes, of course! Thanks for reminding me. (This was the result of too quickly switching from a version using a trailing blank.)
Thank you, everyone!!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.