BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;
2 REPLIES 2
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
ballardw
Super User

Read The Friendly Manual

or at least the online help.

There is an example in the Proc Means documentation named

Identifying the Top Three Extreme Values with the Output Statistics

Replace the OUT[3] with OUT[2] and use MIN instead of MAX

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 262 views
  • 2 likes
  • 3 in conversation