1

I am trying to show only one decimal in a two-way table in SAS. This is the code I used for a one-way table (and it works):

ods path (prepend) patients01;
PROC TEMPLATE;
define table base.freq.onewayfreqs;
parent = base.freq.onewayList;
column line fvariable flistvariable variable frequency testfrequency percent testpercent cumfrequency cumpercent;
define percent;
format = 8.1;
end;
end;
run;

PROC FREQ data = patients01;
tables gender;
run;

The table I want to show is this here:

PROC FREQ data = patients01;
tables gender * pattern;
run;

I have tried this but it doesn't work:

PROC FREQ data = patients01;
tables gender * pattern / FORMAT=COMMA6.;
run;

Does anyone know how I can do this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

Replace "onewayfreqs"

with "CrossTabFreqs"

Shawn
  • 1
0

FORMAT= specifies only certain things; from the helptext:

[Syntax: FORMAT=format-name]

Specifies a format for the following crosstabulation table cell values: frequency, expected frequency, and deviation.

The easiest way to do this really is to use proc tabulate, where you have direct control over nearly everything (if you want to understand how to do that, read the docs, give it a try, then ask separately if you need more help). However, this is doable in the same manner as above.

You can override other elements using the same method you did so for onewayfreqs. I did that below, just taking the basic CROSSTABFREQS template first using SOURCE, then modifying it. You may want to further modify it.

ods path (prepend) work.templat(update);
proc template ;

 
 define crosstabs Base.Freq.Crosstabfreqs;
    notes "Crosstabulation table";
    cellvalue Frequency Expected Deviation CellChiSquare TotalPercent Percent RowPercent ColPercent CumColPercent;
    header TableOf ControllingFor;
    footer NoObs Missing;
 
    define TableOf;
       dynamic StratNum NoTitle;
       text "Table " StratNum 10. " of " _ROW_NAME_ " by " _COL_NAME_ / (NoTitle=0) and (StratNum>0);
       text "Table of " _ROW_NAME_ " by " _COL_NAME_ / NoTitle=0;
    end;
 
    define ControllingFor;
       dynamic StratNum StrataVariableNames StrataVariableLabels;
       text "Controlling for" StrataVariableNames / StratNum>0;
    end;
 
    define header RowsHeader / nolist;
       text _ROW_NAME_ "(;" _ROW_LABEL_ ")" / _ROW_LABEL_ not = '';
       text _ROW_NAME_;
       cindent = ";";
       space = 0;
    end;
 
    define header ColsHeader / nolist;
       text _COL_NAME_ "(;" _COL_LABEL_ ")" / _COL_LABEL_ not = '';
       text _COL_NAME_;
       cindent = ";";
       space = 1;
    end;
 
    define Missing;
       dynamic FMissing;
       text "Frequency Missing = " FMissing -12.99 / FMissing not = 0;
       space = 1;
    end;
 
    define NoObs;
       dynamic SampleSize;
       text "Sample Size = 0" / SampleSize=0;
       space = 1;
    end;
 
    define Frequency;
       header = "Frequency";
       format = BEST7.;
       label = "Frequency Count";
       print;
       data_format_override;
    end;
 
    define Expected;
       header = "Expected";
       format = BEST6.;
       label = "Expected Frequency";
       print;
       data_format_override;
    end;
 
    define Deviation;
       header = "Deviation";
       format = BEST6.;
       label = "Deviation from Expected Frequency";
       print;
       data_format_override;
    end;
 
    define CellChiSquare;
       header = "Cell Chi-Square";
       format = BEST6.;
       label = "Cell Chi-Square";
       print;
    end;
 
    define TotalPercent;
       header = "Tot Pct";
       format = 6.1;
       label = "Percent of Total Frequency";
       print;
    end;
 
    define Percent;
       header = "Percent";
       format = 6.1;
       label = "Percent of Two-Way Table Frequency";
       print;
    end;
 
    define RowPercent;
       header = "Row Pct";
       format = 6.1;
       label = "Percent of Row Frequency";
       print;
    end;
 
    define ColPercent;
       header = "Col Pct";
       format = 6.1;
       label = "Percent of Column Frequency";
       print;
    end;
 
    define CumColPercent;
       header = %nrstr("Cumulative Col%%");
       format = 6.1;
       label = "Cumulative Percent of Column Frequency";
       print;
    end;
    cols_header = ColsHeader;
    rows_header = RowsHeader;
 end;
run;


proc freq data=sashelp.cars ;
  tables origin*make;
run;
Joe
  • 62,789
  • 6
  • 49
  • 67