Desktop productivity for business analysts and programmers

proc univariate problem

Reply
Occasional Contributor
Posts: 7

proc univariate problem

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

Grand Advisor
Posts: 10,223

Re: proc univariate problem

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.

Occasional Contributor
Posts: 7

Re: proc univariate problem

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.

Occasional Contributor
Posts: 7

Re: proc univariate problem

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.

Grand Advisor
Posts: 9,593

Re: proc univariate problem

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

Ask a Question
Discussion stats
  • 4 replies
  • 339 views
  • 0 likes
  • 3 in conversation