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

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