BookmarkSubscribeRSS Feed
arunvaibhav2
Calcite | Level 5

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

 

1 REPLY 1
WarrenKuhfeld
Ammonite | Level 13

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

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
  • 1 reply
  • 962 views
  • 0 likes
  • 2 in conversation