How can I control the output vaiable sort order when I don't have a Class statement. I want them to be alphabetical.
Tammy
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
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.
The Variable list
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;
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;
Send the data to an output dataset and sort by variable name or possibly label as makes more sense.
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
perfect solution -I should have thought of this -guess I was trying to make it harder than it needed to be -Thank you
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.