BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

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();
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

6 REPLIES 6
AhmedAl_Attar
Ammonite | Level 13

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 

DavidPhillips2
Rhodochrosite | Level 12

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();

 

ballardw
Super User

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.

DavidPhillips2
Rhodochrosite | Level 12

Ballardw,

 

Thanks for explaining the &&.  That helps a lot.  I think i'm close to working through the multiple dynamic prompts.

DavidPhillips2
Rhodochrosite | Level 12

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;
ballardw
Super User

@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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 725 views
  • 2 likes
  • 3 in conversation