BookmarkSubscribeRSS Feed
deleted_user
Not applicable
In a macro, when I use this code


proc sql ;
select min(score) into: S from test;
create table test_ as select *, min(score) as minimum from test;
quit;

proc sql;
select count(*) into: C from test_ where score = minimum;
quit;

data final;
set test;
%if %eval(&C.)=1 %then %do;
%if score=&S %then %let grade=0.80;
%else %let grade=0.05;
%end;
run;



Doesn't throw up error, neither the expected result.

Any suggesstions appreciated.

Thanks
2 REPLIES 2
NickR
Quartz | Level 8
I see a problem with your data step.

Try this...

%let s = 20;
%let c = 1;

data test;
score = 20;
run;

%macro test;
data final;
set test;
%global grade;
%if %eval(&C)=1 %then %do;
if score=&S then call symput ('grade','0.80');
else call symput ('grade','0.05');
%end;
run;
%mend test;

%test;

%put &grade;
deleted_user
Not applicable
Nick, thanks for that quick reply.
one question, what if my score and grade need to be variables (say with 10 observations) in final dataset?

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