DATA Step, Macro, Functions and more

My Macro resolved to previous result while log resolves to current. Any help?

Reply
Occasional Contributor
Posts: 6

My Macro resolved to previous result while log resolves to current. Any help?

[ Edited ]

Hello all,

 

Below is the code.

 

 

options mprint symbolgen;

data have; input EMPNO Salary empcode $; cards; 111 4000 A 112 6000 A 114 2000 A 115 8000 A 223 2000 B 226 1000 B 228 3000 B 300 500 C 333 700 C 345 300 C 356 200 C 320 700 C ; run; %macro highest(num=); %global g_num; %let g_num = #
proc sort data=have; by descending salary; run;
data want; set have; if _n_ = &g_num then do; output; stop; end; run; proc print data = want;
%if &g_num = 1 %then %do; title "This is 1st Highest Salary"; %end; %else %if &g_num = 2 %then %do; tilte "This is 2nd Highest Salary"; %end; %else %if &g_num = 3 %then %do; title "This is 3rd Highest Salary"; %end; %else %do; title "This is &g_num.th Highest Salary"; %end;
%symdel g_num;
%mend highest;
%highest(num=11)

 

 

I want to print nth highest salary.

 

At first my program executes fine. And If you execute changing the parameter value(num) in macro %highest, along with macro it yields correct results.

 

But if I execute only the line  %highest(num=11) by changing the value, without including the macro definition in the execution, it shows results of previous value. 

 

What's wrong with this code ? 

 

Thanks,

Vaibhav

 

SAS Super FREQ
Posts: 496

Re: My Macro resolved to previous result while log resolves to current. Any help?

Posted in reply to arunvaibhav2

Spell title correctly throughout.  Your second one is spelled wrong.  Add a RUN statement at the end.

Ask a Question
Discussion stats
  • 1 reply
  • 55 views
  • 0 likes
  • 2 in conversation