- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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