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
Spell title correctly throughout. Your second one is spelled wrong. Add a RUN statement at the end.
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.
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.