macro error

Reply
Super Contributor
Posts: 312

macro error

I wrote a macro and have error when running it. Can anyone give me some hints? Thank you.

 

%let dupi_list= 055de0f8c73c03f36667ef0cb1a46ad4dee09333,
		321eadc33bf8fa151ce7e0332fe933628bb850df,
		c56d0d0b4eb34dcef8564b9d6f3d6905cb366b8b,
		adc3bafc593bdfab5fb4419d63436707f531ade2,
		dab5f2768160ce010a3b9a6af40d8e93c050b9e0,
		dbf0c60a4a84af28c94b95f15b2937cd8d205333,
		712ec5bc5bc21c0f19642c9a2b2792350a9527dd,
		453062a2e82c936c8f4ca108dafc2970469a0128,
		5ceedef354733c16ed3c6205cc270528402551ab,
		cfc38a7619ba2be1c92c25c336108abdf5d57c41;
%Macro plot; %local i next_dupi; %let i=1; %do %while (%scan(&dupi_list, &i) ne ); %let next_dupi = %scan(&dupi_list, &i); %** DO whatever needs to be done for &NEXT_NAME; Proc SGplot data = top10.top10_daily_wager ; where DUPI="&next_dupi"; series x=date y=sum_wager_day / LineAttrs= (pattern=1 color="black"); run; %let i = %eval(&i + 1); %end; %mend plot;

%plot;

The error says:

ERROR: Macro function %SCAN has too many arguments.
ERROR: The macro PLOT will stop executing.

Frequent Contributor
Posts: 123

Re: macro error

In your %do %while statement, you don't have any condition after the not equals:

 

%do %while (%scan(&dupi_list, &i) ne );

I believe there's nothing wrong with the %scan function, its just that you have the ne with no condition after it. Hope this helps.

 

 

Super Contributor
Posts: 312

Re: macro error

%Macro plot2;
%local i next_dupi;
%do i=1 %to %sysfunc(countw(&dupi_list));
   %let next_dupi = %scan(&dupi_list, &i);
   %** DO whatever needs to be done for &NEXT_NAME;
      Proc SGplot  data = top10.top10_daily_wager ;
	where DUPI="&next_dupi";
	series x=date y=sum_wager_day /
	LineAttrs= (pattern=1 color="black");
run;
%end;
%mend plot2;

%plot2;

with this loop, I got error :

ERROR: The function COUNTW referenced by the %SYSFUNC or %QSYSFUNC macro function has too many
       arguments.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is
       required. The condition was: %sysfunc(countw(&dupi_list))
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro PLOT2 will stop executing.

Super Contributor
Posts: 312

Re: macro error

%macro loop(dupi_list);
%let i=1;
%do %while (%scan(&dupi_list, &i, ,) ^=%str());
%let next_dupi=%scan(&dupi_list, &i, ,); 
%put &next_dupi;

*rest of SAS code goes here;
Proc SGplot  data = top10.top10_daily_wager ;
	where DUPI="&next_dupi";
	series x=date y=sum_wager_day /
	LineAttrs= (pattern=1 color="black");
run;


*Increment counter;
%let i=%eval(&i+1);
%end;
%mend;

%loop(&dupi_list);

The third loop, I got :

ERROR: More positional parameters found than defined.

 

Trusted Advisor
Posts: 1,114

Re: macro error

Hi @fengyuwuzu,

 

Your %WHILE condition ("... ne ") is fine, but you need to mask the commas in &dupi_list by using a macro quoting function such as %BQUOTE, so that they are not misinterpreted as delimiters of "too many arguments" of the %SCAN function or of "positional parameters" that have not been defined:

%scan(%bquote(&dupi_list), &i)
Grand Advisor
Posts: 17,290

Re: macro error

If your macro contains only the code shown, PROC SGPLOT, you'd be better off using a BY statement and don't need a macro at all. 

Super User
Super User
Posts: 6,304

Re: macro error

You should always try to use spaces or something other than comma as your delimter.

 

 

%let dupi_list=1 2 3 4;
%let next_dupi = %scan(&dupi_list,&i);

or

%let dupi_list=1|2|3|4;
%let next_dupi = %scan(&dupi_list,&i,|);

Commas just cause trouble.

Ask a Question
Discussion stats
  • 6 replies
  • 396 views
  • 0 likes
  • 5 in conversation