Hello
I want to calculate value in second smallest observation .
I want to calculate value in first smallest observation .
I know to calculate it when the values are in wide structure using smallest function.
My question-
Is it possible to calculate it also when values are in long structure?
I am using proc summary to calculate also other statistics and here SAS knows to calculate it on long structure.
Is it possible to calculate second smallest via proc summary?
data trans;
input Cust_ID 1-4 VAR $ 6-7 col1;
cards;
3188 H1 640
3188 H1 980
3188 H1 1400
3188 H1 3400
3188 H1 4000
3188 H1 8200
3188 H2 0
3188 H2 0
3188 H2 0
3188 H2 0
3188 H2 500
3188 H2 500
3188 H3 0
3188 H3 250
3188 H3 250
3188 H3 250
3188 H3 275
3188 H3 800
3188 H4 20
3188 H4 10
3188 H4 20
3188 H4 20
3188 H4 20
3188 H4 10
;
Run;
proc summary data=trans nway;
class Cust_ID var;
var col1;
output out=summary (drop=_type_ _freq_) cv=CV mean= mean n=n std=std/autoname;
run;
proc transpose data=trans out=Wide;
by Cust_ID vAR;
VAR col1;
Run;
data summary_b;
set Wide;
Second_Smallest=smallest(2,Col1,Col2,Col3,Col4,Col5,Col6) ;
First_Smallest=smallest(1,Col1,Col2,Col3,Col4,Col5,Col6) ;
Run;
proc sql;
create table want as
select a.*,b.Second_Smallest,b.First_Smallest
from summary as a
left join summary_b as b
on a.Cust_ID=b.Cust_ID and a.VAR=b.VAR
;
quit;
@Ronein wrote:
I want to calculate value in second smallest observation .
I want to calculate value in first smallest observation .
What does "second smallest observation" mean?
Or do you mean 2nd smallest value of a particular variable?
If that's what you mean, Google is your friend. This has been asked many times in this forum, all you have to do is search for it.
Read The Friendly Manual
or at least the online help.
There is an example in the Proc Means documentation named
Replace the OUT[3] with OUT[2] and use MIN instead of MAX
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.