Help using Base SAS procedures

How to get the variable list in the descending order of their mean values?

Reply
Contributor
Posts: 36

How to get the variable list in the descending order of their mean values?

For example, I have one dataset:mydata. How to get the variable list in which var1-var4 are sorted by the descending order of their mean values?

Thanks!!

data mydata;

input var1 var2 var3 var4;

datalines;

1 2 3 4

1 3 1 6

4 5 8 9

2 8 2 2

;

run;

Super Contributor
Posts: 349

Re: How to get the variable list in the descending order of their mean values?

Hi,

data mydata;

input var1 var2 var3 var4;

xx=mean(of var1-var4);

datalines;

1 2 3 4

1 3 1 6

4 5 8 9

2 8 2 2

;

run;

proc sort data=mydata;by descending xx;run;

Thanks,

Shiva

Esteemed Advisor
Posts: 7,058

Re: How to get the variable list in the descending order of their mean values?

Depend upon what you actually want.  E.g., it might require something like the following if you actually want the dataset variables to be reordered:

data mydata;

input var1 var2 var3 var4;

datalines;

1 2 3 4

1 3 1 6

4 5 8 9

2 8 2 2

;

proc means data=mydata noprint;

  output out=var_means(drop=_FREQ_ _TYPE_);

run;

proc transpose data=var_means out=trans_mean(rename=(_NAME_=NAME));

  id _STAT_;

run;

proc sql noprint;

  select name into :names

    separated by " "

      from trans_mean

        order by mean desc

  ;

quit;

data want;

  retain &names.;

  set mydata;

run;

Ask a Question
Discussion stats
  • 2 replies
  • 123 views
  • 1 like
  • 3 in conversation