DATA Step, Macro, Functions and more

URGENT ! numeric value of a global macro as an input to a macro?

Reply
Contributor
Posts: 60

URGENT ! numeric value of a global macro as an input to a macro?

Hi,

i cant make this work and it's very urgent, please help!

this is the log :

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &NOBSI
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro ADJUST will stop executing.




This is the code:




data _null_;
set list1 nobs=nobs;
call symputn ('NOBSI',nobs);
stop;
run;


%macro ADJUST(NOBSI);

%do I=1 %TO &NOBSI;
.etc
.etc
.etc
.
%end;

%mend; /*end of macro*/

/* here I create a datastep in order to be able to use symget

data A;
NOBSI=SYMGETn ('NOBSI');

%ADJUST(NOBS) ;

RUN;
Super Contributor
Super Contributor
Posts: 365

Re: URGENT ! numeric value of a global macro as an input to a macro?

Posted in reply to sasuser1000
Hello SASUser1000,

I found 2 problems with your code:

1. In data _null_; it should be call symputx ('NOBSI',nobs);
2. In data A it is impossible to create macro variable and use it in the same datastep.

This is a correct veriosn of your program:
[pre]
data list1;
do i=1 to 10;
output;
end;
run;
data _null_;
set list1 nobs=nobs;
call symputx ('NOBSI',nobs);
stop;
run;


%macro ADJUST(NOBSI);
%local i;
%do I=1 %TO &NOBSI;
%put i=&i;
%end;
%mend; /*end of macro*/

%adjust(&nobsi)
[/pre]

Sincerely,
SPR
Contributor
Posts: 60

Re: URGENT ! numeric value of a global macro as an input to a macro?

Dear SPR!

Thank you so much, it worked!
Ask a Question
Discussion stats
  • 2 replies
  • 109 views
  • 0 likes
  • 2 in conversation