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
Rhodochrosite | Level 12

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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