kuchbi_code
kuchbi_code

Reputation: 11

Storing Proc mean variables in SAS

    proc means data=har.&seg_cell n mean std p1 p50 p99;
    class segment;
    var txn tpv;
    output out=stat_1 (drop = _TYPE_ _FREQ_) 
    P1(txn)=txn_P1_T P1(tpv)=tpv_P1_T
    P99(txn)=txn_P99_T P99(tpv)=tpv_P99_T
    ;
    where POS_flag = &POS and cell=&gcell;
    title "Stat Summary - Test_POS";
    run;

    data har.&seg_cell;
    if _N_=1 then set stat_1; 
    set har.&seg_cell;
    run;

I want to save the P1 P50 P99 for both TXN and TPV Segment wise(segment has 10 different names) into separate variables. But when ever I run this code only the overall(all segments) P1 P50 P99 getting stored for all the rows.

what I want is depending on the segment that particula P1 P50 P99 should be added.

Please kindly help me with this and pardon me for my bad vocab.

Upvotes: 0

Views: 538

Answers (3)

BellevueBob
BellevueBob

Reputation: 9618

You need to:

  1. Sort your source data set by segment
  2. Use the NWAY option to eliminate the "grand total" observation from the MEANS output data set (_TYPE_=0).
  3. Merge the output data set back to your source.

So, a complete solution should be something like this:

proc sort data=har.&seg_cell;
   by segment;
run;
proc means nway data=har.&seg_cell n mean std p1 p50 p99;
  class segment;
  var txn tpv;
  output out=stat_1 (drop = _TYPE_ _FREQ_) 
         P1(txn)=txn_P1_T P1(tpv)=tpv_P1_T
         P99(txn)=txn_P99_T P99(tpv)=tpv_P99_T;
  where POS_flag = &POS and cell=&gcell;
  title "Stat Summary - Test_POS";
run;

data har.&seg_cell;
   merge har.&seg_cell stat_1;
      by segment;
run;

Upvotes: 1

Michael Richardson
Michael Richardson

Reputation: 4282

If you want the summary data for each segment merged into the proper rows, you will need to do a merge by instead of using if _N_=1.

Upvotes: 0

Hong Ooi
Hong Ooi

Reputation: 57686

Try using by segment instead of class. Note you'll have to sort your dataset by segment first.

Upvotes: 0

Related Questions