Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add new observation to dataset based on original observations? 1

Status
Not open for further replies.

on818come

Programmer
Oct 6, 2008
22
US
Actually it derives from a stupid question.
I have the data file like

Ulti Part Tply
120.00 86.11 0.0064
119.00 84.22 0.0063
123.00 86.90 0.0065
117.00 83.11 0.0063
120.00 85.91 0.0062

I expect to get statistics result by proc mean including CV and output to a new dataset like
Ulti Part Tply
Mean
Min
Max
CV
STDDEV
N

I can't get CV line from proc mean.
So I hope to calculate it from STDDEV/MEAN
Hoo to do it?

I 'm really appreciate your help,The format is too hard to adjust.
 
If you want to calculate CV manually as STD/MEAN, then you can either use a transpose, do the calculation, and then transpose back. Otherwise you can handle it with arrays.

Code:
 data have;
   input Ulti          Part        Tply;
   cards;
120.00       86.11        0.0064
119.00       84.22        0.0063
123.00       86.90        0.0065
117.00       83.11        0.0063
120.00       85.91        0.0062
   ;run;

proc means data=have noprint;
   output out=stats(drop=_type_ _freq_);
    run;

data want;
   array all [3] Ulti Part Tply;
   array val [3] _temporary_;
   set stats;
   if _stat_ = 'MEAN' then do _n_=1 to dim(all);
      val[_n_]=all[_n_];
      end;
   else if _stat_ = 'STD' then do;
      output;
      _stat_='CV';
      do _n_=1 to dim(all);
         all[_n_]=all[_n_]/val[_n_];
         end;
      end;
   output;
   run;
 
You can also call the CV statistic in the output statement like so:

Code:
proc means data=have noprint;
   output out=stats(drop=_type_ _freq_)
   CV(Ulti Part Tply)=CV_Ulti CV_Part CV_Tply;
run;

This example would only give the CV values however, and if you add lines for each statistic (N, MIN, MEAN..etc) it would create a new column for each stat....missing out on the clean look the array will give you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top