DATA Step, Macro, Functions and more

Macro

Reply
N/A
Posts: 0

Macro

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
Frequent Contributor
Posts: 81

Re: Macro

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;
N/A
Posts: 0

Re: Macro

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?
Ask a Question
Discussion stats
  • 2 replies
  • 110 views
  • 0 likes
  • 2 in conversation