i have programm:
//////////////////////////////////////////////////////
proc means data=temp noprint nway;
var Name_of_var;
output out = temp (drop= _:)
n = N mean = Mean STD = SD median = Median min = Min max = Max;
run;
proc transpose data = temp out = temp prefix = col;
var N Mean SD Median Min Max;
format N 2. Mean 4.1 SD 5.2 Median 4.1 Min 3. Max 3.;
run;
/////////////////////////////////////////////////////
My result:
N=35
Mean = 59.2343123412
SD = 64.27498279
Median=41
Min=70
max=130
!!!
I see wrong result (without format).
A column in SAS can have only one format. Your results from proc means has multiple columns with multiple formats.
When you transpose it to get them stacked, it assumes the format. If it assumed a format without decimals, that may not be what you want. I have no idea what you actually want right now either so I'm assuming it's a format issue. Or is proc means not generating the correct output?
Please define wrong result?
Most likely you're combining multiple fields that have different formats, so yes, you will need to explictly set the format so that things display properly.
After proc means i have only 1obs:
N Mean SD median min max
1 35 59.2343123412 64.27498279 41 70 130
A column in SAS can have only one format. Your results from proc means has multiple columns with multiple formats.
When you transpose it to get them stacked, it assumes the format. If it assumed a format without decimals, that may not be what you want. I have no idea what you actually want right now either so I'm assuming it's a format issue. Or is proc means not generating the correct output?
Your result dataset contains a single numeric variable, COL1. This variable has no chance to show its values in a variety of different formats such as 2., 4.1, 5.2 and so on, depending on the values of variable _NAME_.
The FORMAT statement in your PROC TRANSPOSE step refers to the input dataset, not to the output dataset. Nevertheless, it can have an impact on the output dataset, if the transposed variable is character. If you're happy with a character variable COL1 (e.g. for reporting purposes), you could add a dummy character variable to the input dataset and transpose it, in order to force COL1 to be created as a character variable:
proc means ...
...
data temp;
set temp;
dummy=' ';
run;
proc transpose data = temp out = temp(where=(upcase(_name_) ne 'DUMMY')) prefix = col;
var N Mean SD Median Min Max dummy;
format N 2. Mean 4.1 SD 5.2 Median 4.1 Min 3. Max 3.;
run;
Now, the values of COL1 are nicely formatted (but character).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.