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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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