BookmarkSubscribeRSS Feed
sasuser1000
Calcite | Level 5
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;
2 REPLIES 2
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
sasuser1000
Calcite | Level 5
Dear SPR!

Thank you so much, it worked!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 969 views
  • 0 likes
  • 2 in conversation