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?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 779 views
  • 0 likes
  • 2 in conversation