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

Hi,

Can you please help me with this looping process through name stored in NAMELIST variable?

I am not sure what is missing.

Thanks a lot!

Harry

 

The Error notice is:

ERROR: Macro function %SCAN has too many arguments. The excess arguments will be ignored.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: Alice
ERROR: Argument 2 to macro function %SCAN is not a number.
name 1 is
ERROR: The macro DOPRINT will stop executing.

proc sql ;
select name into :NAMELIST  separated by ','
from sashelp.class
; quit;
%put &NAMELIST ;

%macro doprint;
	%do i=1 %to 10;
		%put name &i is %scan(&NAMELIST,&i);
	%end;
%mend;
%doprint;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Commas are the delimiter in the %scan function. You have placed commas in the body of your NAMELIST variable. So each comma appearing inside Namelist is treated as a delimiter resulting in "too many" parameters.

 

Your shown code will work if you use "separated by ' ' " in the select into.

Or use a quoting function to "hide" the commas from that use such as

%scan(%bquote(&NAMELIST) ,&i);

 

 

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

This is a duplicate question. Please do not post duplicate questions. I have answered your question in your other thread at https://communities.sas.com/t5/SAS-Programming/Proc-SQL-save-multiple-value-to-macro-variable/td-p/6...

--
Paige Miller
ballardw
Super User

Commas are the delimiter in the %scan function. You have placed commas in the body of your NAMELIST variable. So each comma appearing inside Namelist is treated as a delimiter resulting in "too many" parameters.

 

Your shown code will work if you use "separated by ' ' " in the select into.

Or use a quoting function to "hide" the commas from that use such as

%scan(%bquote(&NAMELIST) ,&i);

 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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