sasssasdecimal-pointdatastepprocstat

how to control decimal point in SAS output dataset?


I am new to SAS programming and I trying to work on proc means statement. For controlling my decimal value in the output I have used maxdec option however when I tried to assign a new dataset to the output and print it my decimal values are not controlled in the standard deviation. can someone help me figure out how to control the decimal points in the output dataset?? here is the code I used:

proc means data=sashelp.class maxdec=2 noprint;
var height weight;
output out=dsn2 Mean= Median= Min= Max= STD=/autoname;
run; 
proc print data=dsn2;
run;


Solution

  • The MAXDEC option just controls how the PRINTOUT is generated.

    If you want to control the number of decimal places used when printing a dataset you need to attach a format to the variable(s). To control the formats attached to variables in PROC MEANS use a FORMAT statement. If you attach a format to the analysis variable then the same format will be attached to any statistic derived from that variable.

    So you could use a FORMAT statement in the PROC MEANS step, or when creating the input dataset. Or you could attach the format to the variable in the output dataset later, or just during the PROC PRINT.

    data class ;
      set sashelp.class;
      format height weight 6.2;
    run;
    
    proc means data=class maxdec=2 noprint;
      var height weight;
      output out=dsn2 Mean= Median= Min= Max= STD=/autoname;
    run; 
    proc contents data=dsn2 varnum; run;
    

    Result

             Variables in Creation Order
    
     #    Variable         Type    Len    Format
    
     1    _TYPE_           Num       8
     2    _FREQ_           Num       8
     3    Height_Mean      Num       8    6.2
     4    Weight_Mean      Num       8    6.2
     5    Height_Median    Num       8    6.2
     6    Weight_Median    Num       8    6.2
     7    Height_Min       Num       8    6.2
     8    Weight_Min       Num       8    6.2
     9    Height_Max       Num       8    6.2
    10    Weight_Max       Num       8    6.2
    11    Height_StdDev    Num       8    6.2
    12    Weight_StdDev    Num       8    6.2
    

    Note that PROC MEANS will even let you attach a format to the generated statistic variables directly, but you will get a WARNING about variable not found in the input dataset.

    2693   proc means data=sashelp.class maxdec=2 noprint;
    2694   var height weight;
    2695   format height_mean weight 6.2 ;
    WARNING: Variable HEIGHT_MEAN not found in data set SASHELP.CLASS.
    2696   output out=dsn2 Mean= Median= Min= Max= STD=/autoname;
    2697   run;