Hello all,
Not sure why but I am unable to automate this portion:
%macro title();
%let allCodes = %sysfunc(CATX(",", &Codes1, &Codes2, &Codes3, &Codes4 ));
%put &allCodes;
%mend;
%title();
I am doing this below for automating the above %let allCodes statement - but seeing errors:
%macro attempt1();
%do i = 1 %TO 3;
%let allCodes = %sysfunc(CATX(",", &Codes&i.
%end;
&Codes4 ));
%put &allCodes;
%mend;
attempt1();
Just trying to automate the macro title() using DO loop but it gives errors...any ideas would be highly appreciated.
Regards,
Tina
When you run this
%let string1 = I like;
%let string2 = Kermit;
%let string3 = the;
%let string4 = Frog;
%put &=string1 &=string2 &=string3 &=string4;
%macro attempt ;
%global allcodes allcodes2;
%let allCodes =;
%do i = 1 %TO 4;
%let allCodes = &allCodes &&string&i;
%if &i = 1 %then %let allcodes2 = (&&string&i;
%else %let allcodes2 = &allcodes2 &&string&i;
%end;
%let allcodes2 = &allcodes2)%str(;);
%put &=allCodes &=allcodes2;
%mend attempt;
%attempt
Then &allcodes should have all 4 strings and allcodes2 should have parens and a semi-colon.
Cynthia
don't you need to array codes1 through codes3 before you us the do I = 1 to 3?
Hi:
There is no need to use %SYSFUNC or the CATX function. Consider this:
%let string1 = I like;
%let string2 = Kermit;
%let string3 = the;
%let string4 = Frog;
%let bigstring = &string1 &string2 &string3 &string4;
%put &=string1 &=string2 &=string3 &=string4;
%put &=bigstring;
and if I wanted to make BIGSTRING2 with a different character between the values, I could do this:
%let bigstring2 = &string1~&string2#&string3^&string4;
%put &=bigstring2;
CATX and SYSFUNC are not needed in what you describe.
Cynthia
Hi Cynthia,
Thing is this:
I have a couple of codes like office visit codes, well child visit codes.
So currently it is two sets of codes:
%let Codes1 = "a" "b"; /* office visit codes */
%let Codes2 = "c" "d" "e"; /* well child visit codes */
%let allCodes = &Codes1. &Codes2.; /* this macro var allCodes will contain all codes that were separately defined above */
%put &allCodes.;
/* "a" "b" "c" "d" "e" */
Eventually, a user will add other codes like dental codes, back pain codes, custom codes like this:
%let Codes3 = "aa" "bb" "cc"; /* dental */
%let Codes4 = "xx" "yy" "zz"; /* Back pain codes */
%let Codes5 = "aaa" "bbb" "ccc" /* arthritis codes */
And I wanted the &allCodes macro variable to now contain all of these additional codes as well without me having to update the code like in this below:
%let allCodes = &Codes1. &Codes2. &Codes3. &Codes4. &Codes5.; /* Do not want to append codes like this to update &allCodes because there could be 50 of such code types a user can add*/
This is why I was trying to use the macro above..
I need to update the &allCodes for future proc freq etc purposes.
When you run this
%let string1 = I like;
%let string2 = Kermit;
%let string3 = the;
%let string4 = Frog;
%put &=string1 &=string2 &=string3 &=string4;
%macro attempt ;
%global allcodes allcodes2;
%let allCodes =;
%do i = 1 %TO 4;
%let allCodes = &allCodes &&string&i;
%if &i = 1 %then %let allcodes2 = (&&string&i;
%else %let allcodes2 = &allcodes2 &&string&i;
%end;
%let allcodes2 = &allcodes2)%str(;);
%put &=allCodes &=allcodes2;
%mend attempt;
%attempt
Then &allcodes should have all 4 strings and allcodes2 should have parens and a semi-colon.
Cynthia
Thank you so much for this, I highly appreciate it.
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.