DATA Step, Macro, Functions and more

Proc transpose produces wrong result without format statement

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Proc transpose produces wrong result without format statement

[ Edited ]

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


Accepted Solutions
Solution
‎04-08-2016 01:27 PM
Super User
Posts: 19,861

Re: proc transpose with format st.(wrong result)

Posted in reply to Konstantin123

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


All Replies
Super User
Posts: 19,861

Re: proc transpose with format st.(wrong result)

Posted in reply to Konstantin123

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. 

 

 

New Contributor
Posts: 4

Re: proc transpose with format st.(wrong result)

After proc means i have only 1obs:

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

Solution
‎04-08-2016 01:27 PM
Super User
Posts: 19,861

Re: proc transpose with format st.(wrong result)

Posted in reply to Konstantin123

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?

 

 

Trusted Advisor
Posts: 1,118

Re: proc transpose with format st.(wrong result)

Posted in reply to Konstantin123

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

 

 

☑ This topic is solved.

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

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