BookmarkSubscribeRSS Feed
jaselig
Calcite | Level 5

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

4 REPLIES 4
ballardw
Super User

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.

jaselig
Calcite | Level 5

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

VAR1VAR2MAX
Johnstore1105
Johnstore2104

i need same data plus var4 and var 5 from data1

VAR1VAR2MAXvar4var5
Johnstore1105465city2
Johnstore210415444city4

thanks in advance.

jaselig
Calcite | Level 5

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

VAR1VAR2MAX
Johnstore1105
Johnstore2104

i need same data plus VAR4 and VAR 5

VAR1VAR2MAXvar4var5
Johnstore1105465city2
Johnstore210415444city4

thanks in advance.

Ksharp
Super User

You missed a variable in MERGE.

Code: Program

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 4 replies
  • 1215 views
  • 0 likes
  • 3 in conversation