BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Konstantin123
Fluorite | Level 6

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). 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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?

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User

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. 

 

 

Konstantin123
Fluorite | Level 6

After proc means i have only 1obs:

   N   Mean                   SD                   median    min max
1 35 59.2343123412   64.27498279   41           70   130

Reeza
Super User

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?

 

 

FreelanceReinh
Jade | Level 19

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 950 views
  • 2 likes
  • 3 in conversation