Somehow the value of curProgramList1 is transformed from BS-MAC-PB1 to BSMAC-PB1 with the below. and the error message ERROR: Invalid symbolic variable name BSMAC-PB1. is displayed.
%macro ProgramDisplay(); %do i = 1 %to &curProgramList_count; %let curProgram = %superq(&curProgramList&i); %put "Test5"; %put curProgram &curProgram; %if &curProgram eq %then %do; %end; %else %do; %put Test6; %end; %end; %mend; %ProgramDisplay();
Is this what you are looking for:
%macro ProgramDisplay(); %global curProgramList curProgramList1 curProgramList_count; %let curProgramList = BS-MAC-PB; %let curProgramList_count = 1; %if &curProgramList_count = 1 %then %let curProgramList1 = &curProgramList; %put test4 &curProgramList1; %do i = 1 %to &curProgramList_count; %put &i; %let curProgram = &&curProgramList&i.; %put "Test8" curProgram &curProgram; %if "&curProgram." = "" %then %do; %end; %else %do; %put Test6; %end; %end; %mend; %ProgramDisplay();
In the variable &&curProgramList&i. the leading & followed by another tells SAS to "hold on evaluating" then evaluates the bit after the first & , The evaluates the result with the &, so is after one pass &curprogram1
This is in the documentation under Referencing Macro Variables Indirectly,
Useful but can be hard to debug when you see a variable like &&&&this&&bit&that.
David,
I use a custom macro I developed long time ago, that handles Single & Multi value parameters, and returns a delimited string of the selected value(s).
I've attached a copy of the macro code, and it contains a sample usage in the header comments.
Hope this helps,
Ahmed
What can I add to
%let curProgram = &curProgramList.&i.
so that curProgram = the value = curProgramList1 not curProgramList +1
Its returning BS-MAC-PB1
rather than BS-MAC-PB
%macro ProgramDisplay(); %global curProgramList curProgramList1 curProgramList_count; %let curProgramList = BS-MAC-PB; %let curProgramList_count = 1; %if &curProgramList_count = 1 %then %let curProgramList1 = &curProgramList; %put test4 &curProgramList1; %do i = 1 %to &curProgramList_count; %put &i; %let curProgram = &curProgramList.&i.; %put "Test8" curProgram &curProgram; %if "&curProgram." = "" %then %do; %end; %else %do; %put Test6; %end; %end; %mend; %ProgramDisplay();
Is this what you are looking for:
%macro ProgramDisplay(); %global curProgramList curProgramList1 curProgramList_count; %let curProgramList = BS-MAC-PB; %let curProgramList_count = 1; %if &curProgramList_count = 1 %then %let curProgramList1 = &curProgramList; %put test4 &curProgramList1; %do i = 1 %to &curProgramList_count; %put &i; %let curProgram = &&curProgramList&i.; %put "Test8" curProgram &curProgram; %if "&curProgram." = "" %then %do; %end; %else %do; %put Test6; %end; %end; %mend; %ProgramDisplay();
In the variable &&curProgramList&i. the leading & followed by another tells SAS to "hold on evaluating" then evaluates the bit after the first & , The evaluates the result with the &, so is after one pass &curprogram1
This is in the documentation under Referencing Macro Variables Indirectly,
Useful but can be hard to debug when you see a variable like &&&&this&&bit&that.
Ballardw,
Thanks for explaining the &&. That helps a lot. I think i'm close to working through the multiple dynamic prompts.
This worked
%macro ProgramDisplay(); %global curProgramList1; %if &curProgramList_count = 1 %then %let curProgramList1 = &curProgramList; %put test4 &curProgramList1; %do i = 1 %to &curProgramList_count; %put &i; %let curProgram = &&curProgramList&i.; %put "Test8" curProgram &curProgram; %if "&curProgram." = "" %then %do; %end; %else %do; %put Test6; %end; %end; %mend;
@DavidPhillips2 wrote:
This worked
%macro ProgramDisplay(); %global curProgramList1; %if &curProgramList_count = 1 %then %let curProgramList1 = &curProgramList; %put test4 &curProgramList1; %do i = 1 %to &curProgramList_count; %put &i; %let curProgram = &&curProgramList&i.; %put "Test8" curProgram &curProgram; %if "&curProgram." = "" %then %do; %end; %else %do; %put Test6; %end; %end; %mend;
A minor suggestion which may save you much time later down the road when you start having macros calling each other is to make your diagnostic %put a bit more comprehensive by including variable name and macro scope of variables. This may save having to wade through a bunch of OPTIONS MPRINT SYMBOLGEN output. Something like:
%macro ProgramDisplay(); %global curProgramList1; %if &curProgramList_count = 1 %then %let curProgramList1 = &curProgramList; %put test4 &curProgramList1; %do i = 1 %to &curProgramList_count; %put i = &i in ProgramDisplay; %let curProgram = &&curProgramList&i.; %put "Test8" curProgram &curProgram in ProgramDisplay; %if "&curProgram." = "" %then %do; %end; %else %do; %put Test6 in ProgramDisplay; %end; %end; %mend;
This may be moderately critical if you have the ancient tradition of "%do I=1 %to " in multiple places.
And for added piece of mind if never hurts to have %local i;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.