Help using Base SAS procedures

Proc Means output variable order

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

Proc Means output variable order

How can I control the output vaiable sort order when I don't have a Class statement.  I want them to be alphabetical.

 

Tammy


Accepted Solutions
Solution
‎09-26-2016 05:20 PM
Respected Advisor
Posts: 3,799

Re: Proc Means output variable order

[ Edited ]

You can make your own list of names in the alphabetical order and put them in a macro variable.

 

data class;
   set sashelp.class;
   retain a10 a1 a3 a011 1;
   run;
proc contents data=class(keep=_numeric_) noprint out=names(keep=name);
   run;
proc sql noprint;
   select nliteral(name) into :alphanames separated by ' '
      from names;
   quit;
   run;
%put NOTE: &=alphanames;

You may want to added ORDER=IGNORECASE to PROC CONTENTS to change the order as follows.  PROC CONTENTS "automatically" handles the numeric suffice properly.

 

36         %put NOTE: &=alphanames;
NOTE: ALPHANAMES=a1 a3 a10 a011 Age Height Weight

 

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Proc Means output variable order

I think you'll need to provide a bit more detail. What "them" do you want in alphabetic order? The variables, the statististics, in rows or columns?

 

You may need to provide an example data set and what you want for output for the given example.

Contributor
Posts: 43

Re: Proc Means output variable order

The Variable list

Frequent Contributor
Posts: 123

Re: Proc Means output variable order

The var statement specifies the analysis variables and the order in which they are displayed in the results. You could put them in alphabetical order like the example below.

 

PROC MEANS DATA=people;
  CLASS personID;
  VAR age height sex weight;
  OUTPUT OUT=people2 MEAN= ;
RUN;
Contributor
Posts: 43

Re: Proc Means output variable order

Posted in reply to JediApprentice

Yes, but I have 605 variables so I am using _numeric_ ... so the output is in the internal variable order.  I know I can do this with options on the class statement, but I don't have a class variable.

proc means data=out1.&promo._modelvars n mean median mode std min max skew kurt;
  var _numeric_;
run;

means.JPG

Super User
Posts: 11,343

Re: Proc Means output variable order

Send the data to an output dataset and sort by variable name or possibly label as makes more sense.

Solution
‎09-26-2016 05:20 PM
Respected Advisor
Posts: 3,799

Re: Proc Means output variable order

[ Edited ]

You can make your own list of names in the alphabetical order and put them in a macro variable.

 

data class;
   set sashelp.class;
   retain a10 a1 a3 a011 1;
   run;
proc contents data=class(keep=_numeric_) noprint out=names(keep=name);
   run;
proc sql noprint;
   select nliteral(name) into :alphanames separated by ' '
      from names;
   quit;
   run;
%put NOTE: &=alphanames;

You may want to added ORDER=IGNORECASE to PROC CONTENTS to change the order as follows.  PROC CONTENTS "automatically" handles the numeric suffice properly.

 

36         %put NOTE: &=alphanames;
NOTE: ALPHANAMES=a1 a3 a10 a011 Age Height Weight

 

Contributor
Posts: 43

Re: Proc Means output variable order

Posted in reply to data_null__

perfect solution -I should have thought of this -guess I was trying to make it harder than it needed to be  -Thank you

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 926 views
  • 2 likes
  • 4 in conversation