hi guys , i have a llitle problem using proc univariate
i have a dataset with 4 variables i'm using univariate to get max, min , p99 for one of them.
later y merge a new variable in the data set. with this new variable i need to get the maximun value for p99 for each unique value from this new variable. the problem here is that i need also the correspondent MAX AND MIN for the max p99 i'm unable to get it.
proc univariate data=dat1
noprint;
VAR var4;
by var1 var2;
output out=dat1
pctlpts=99
pctlpre=per_
Min=Min
Max=Max
;
RUN;
proc univariate data=dat1_ noprint;
VAR per_99;
by var1 var3;
;
output out=dat2
Max=maxp99 ;
RUN;
y get a data set with var1 var3 and maxp99 but i need also get the correpondent min y max for the select maxp99
any ideas?
regards
It will help to provide a few initial records of data in a data step and what the expected final output should be.
Since you are using noprint is suspect that what you are looking for may be easier with another approach.
here some dummy data to work with ...
data dat1 ;
LENGTH
var1 $4
var2 $6
var3 8
var4 8
var5 $5;
input
var1 : $CHAR4.
var2 : $CHAR6.
var3 : BEST8.
var4 : BEST8.
var5 : $CHAR5.;
CARDS;
John store1 100 28005 city1
John store1 105 465 city2
John store1 103 12400 city3
John store2 104 15444 city4
John store2 5 45125 city5
John store2 40 45789 city6
John store2 8 9000 city7
;
RUN;
proc univariate data=dat1 noprint;
VAR var3;
by var1 var2;
output out=dat2
Max=MAX ;
RUN;
y get dat2
VAR1 | VAR2 | MAX |
John | store1 | 105 |
John | store2 | 104 |
i need same data plus var4 and var 5 from data1
VAR1 | VAR2 | MAX | var4 | var5 |
John | store1 | 105 | 465 | city2 |
John | store2 | 104 | 15444 | city4 |
thanks in advance.
with this dummy data...
data dat1 ; | |||
LENGTH | |||
var1 $4 | |||
var2 $6 | |||
var3 8 | |||
var4 8 | |||
var5 $5; | |||
input | |||
var1 : $CHAR4. | |||
var2 : $CHAR6. | |||
var3 : BEST8. | |||
var4 : BEST8. | |||
var5 : $CHAR5.; | |||
CARDS; | |||
John store1 100 28005 city1 | |||
John store1 105 465 city2 | |||
John store1 103 12400 city3 | |||
John store2 104 15444 city4 | |||
John store2 5 45125 city5 | |||
John store2 40 45789 city6 | |||
John store2 8 9000 city7 | |||
; | |||
RUN; | |||
proc univariate data=dat1 noprint; | |||
VAR var3; | |||
by var1 var2; | |||
output out=dat2 | |||
Max=MAX ; | |||
RUN; | |||
data dat2 ; | |||
merge dat1 dat2; | |||
by var1 var2; | |||
RUN |
i get dat2 as
VAR1 | VAR2 | MAX |
John | store1 | 105 |
John | store2 | 104 |
i need same data plus VAR4 and VAR 5
VAR1 | VAR2 | MAX | var4 | var5 |
John | store1 | 105 | 465 | city2 |
John | store2 | 104 | 15444 | city4 |
thanks in advance.
You missed a variable in MERGE.
data dat1 ;
LENGTH
var1 $4
var2 $6
var3 8
var4 8
var5 $5;
input
var1 : $CHAR4.
var2 : $CHAR6.
var3 : BEST8.
var4 : BEST8.
var5 : $CHAR5.;
CARDS;
John store1 100 28005 city1
John store1 105 465 city2
John store1 103 12400 city3
John store2 104 15444 city4
John store2 5 45125 city5
John store2 40 45789 city6
John store2 8 9000 city7
;
RUN;
proc univariate data=dat1 noprint ;
VAR var3;
by var1 var2;
output out=dat2 Max=Max;
RUN;
proc sort data=dat1;by var1 var2 var3;run;
data want;
merge dat1(rename=(var3=max)) dat2(in=inb);
by var1 var2 max;
if inb;
RUN;
Xia Keshan
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.