Suppose we hv below data set..
I want to get max month from each obersvations in new variable.
like from 1st obs Mar and in 2nd obs Apr..
data year;
input jan feb mar apr jun;
datalines;
100 234 340 111 231
111 212 213 314 123
run;
By using below code we can calcuate maximum value
data aaa;
set year;
top=max(jan,feb,mar,apr,jun);
run;
Output:
Obs jan feb mar apr jun top
1 100 234 340 111 231 340
2 111 212 213 314 123 314
But i want to find variable which max value??
Please suugest solution?
data want; input jan feb mar apr jun; array list(*) jan--jun; top=max(of list(*)); topvar = vname(list[whichn(max(of list[*]), of list[*])]); datalines; 100 234 340 111 231 111 212 213 314 123 ;
Art, CEO, AnalystFinder.com
Hi Sir,
I am getting below error .. please check.
91 data want;
92 input jan feb mar apr jun;
93 array list(*) jan--jun ;
94 top=max(of list(*));
95 topvar = vname(list[whichn(max(of list[*]), of list[*])]);
------
68
ERROR 68-185: The function WHICHN is unknown, or cannot be accessed.
96 datalines;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0
observations and 7 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
You're obviously using an old SAS version where function WHICHN() hasn't been implemented yet.
Which SAS version are you using?
I'm not aware of a commercial SAS 9.0 version. Here are the commercial versions: http://support.sas.com/techsup/support.html
In case you're using SAS "at home" for educational purposes: Download the free of charge non-commercial version and things will work in a modern environment. https://www.sas.com/en_au/software/university-edition.html
Please execute:
proc setinit;
run;
Then consult the SAS log and tell us which SAS version you see there.
Since you don't have the whichn function, you can simply change that code to use a do loop to identify the corrrect variable:
data want; input jan feb mar apr jun; array list(*) jan--jun; top=max(of list(*)); /* topvar = vname(list[whichn(max(of list[*]), of list[*])]);*/ do i=1 to dim(list); if list(i) eq max(of list[*]) then do; topvar=vname(list[i]); return; end; end; datalines; 100 234 340 111 231 111 212 213 314 123 ;
Art, CEO, AnalystFinder.com
Thanks Sir..
I got solution, This code is working fine.:)
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.