BookmarkSubscribeRSS Feed
Tai_Lopez
Fluorite | Level 6

After figuring out how to add in rows of zeros to a Proc Freq two-way table output, I was able to get the output below in SAS using the Template procedure as well (all titles, row and column labels removed for the sake of anonymity):

 

2
15.38
5
38.46
4
30.77
2
15.38
0
0.00
0
0.00
13
 
0
.
0
.
0
.
0
.
0
.
0
.
0
 
0
0.00
0
0.00
2
66.67
1
33.33
0
0.00
0
0.00
3
 
1
12.50
0
0.00
1
12.50
2
25.00
4
50.00
0
0.00
8
 
0
0.00
1
7.69
5
38.46
3
23.08
4
30.77
0
0.00
13
 
0
.
0
.
0
.
0
.
0
.
0
.
0
 
0
.
0
.
0
.
0
.
0
.
0
.
0
 
0
.
0
.
0
.
0
.
0
.
0
.
0
 
0
0.00
0
0.00
0
0.00
0
0.00
1
100.00
0
0.00
1
 
0
0.00
0
0.00
0
0.00
1
100.00
0
0.00
0
0.00
1
 
0
.
0
.
0
.
0
.
0
.
0
.
0
 
1
6.25
12
75.00
2
12.50
1
6.25
0
0.00
0
0.00
16
 
34
53.13
17
26.56
6
9.38
2
3.13
3
4.69
2
3.13
64
 
0
0.00
0
0.00
2
25.00
1
12.50
5
62.50
0
0.00
8
 
0
0.00
1
100.00
0
0.00
0
0.00
0
0.00
0
0.00
1
 
38
36
22
13
17
2
128

 

What I cannot figure out is if it is possible to somehow change the missing row percents "." to all show as 0.00 or blanks (" ") or anything else that I can specify. Thank you in advance!

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Run this line before PROC FREQ

 

options missing=0;
--
Paige Miller
Tai_Lopez
Fluorite | Level 6
Thank you for the suggestion, unfortunately the row percents still display as periods for the zero rows after running the MISSING= option
ballardw
Super User

Having removed a lot of stuff that might actually have told us what is going on I cannot make a specific code suggestion.

But I might well go to proc tabulate or report. You can assign specific formats for statistics, so you could create a custom format. Or tabulate supports a misstext option that can be more than a single character but that gets applied to all missing values.

 

An example:

proc format;
value missn
. = '0';
value misspct
. = '0.00'
;
run;
proc tabulate data=sashelp.class;
   class sex age;
   tables sex *(n*f=missn. pctn*f=misspct.),
          age
          
   ;
run;

You should have the sashelp.class data set available to test code.

The data set does not have any females age 16 and by default would show missing for both the N and PCTN statistic. The format, overriding the default using <statstic keyword>*f=<formatname.> shows the formatted values.

 

Note: Proc Tabulate does a number of different percents: Pctn, rowpctn, colpctn, tablepctn, pagepctn plus some other tricks. So you need to pay attention to which format. Variables on the CLASS statement behave as in Proc freq and can be counted or percentages calculated. If you add VAR variables they can have statistics like mean, max, min and percentages of sums: pctsum, rowpctsum, colpctsum etc corresponding to the class variable percentages.

 

In the future, if your tables labels are so sensitive, use one of the SAS data sets such as sashelp.class or make your own with generic non-sensitive values. Show a data step to duplicate the data used and the code used to make the table or other output.

 

One is going to guess that proc template with Proc Freq is more work than either Tabulate or Report.

Tai_Lopez
Fluorite | Level 6

I do not have experience with the tabulate procedure, however after modifying it to use my dataset, it does not output the rows of full zeros at all, whereas the freq procedure shown below does.

proc freq data=data;
tables var1*var2 / nocum nocol nopercent;
run;

proc tabulate data=data; class var1 var2; tables var1 * (n rowpctn), var2; run;

 

ballardw
Super User

@Tai_Lopez wrote:

I do not have experience with the tabulate procedure, however after modifying it to use my dataset, it does not output the rows of full zeros at all, whereas the freq procedure shown below does.

proc freq data=data;
tables var1*var2 / nocum nocol nopercent;
run;

proc tabulate data=data; class var1 var2; tables var1 * (n rowpctn), var2; run;

 


Since there is NO DATA there is not way to interpret exactly what you mean by "rows of full zeroes".

Do you mean you expect values with not records to appear in the output? Or what.

 

DATA is really needed to match a "report" format to code to make the report. Note that I provided an actual data set you could use.

One of the behaviors of Proc Tabulate that might cause an issue is that records with missing values of Class variables are excluded from the report. If you expect Var1=3 to appear when Var2 is missing then you you need to add a MISSING option on a class statement.

 

Class var1 var2 / missing;

will treat missing values of the variables as valid levels.

 

But again, data.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 6295 views
  • 1 like
  • 3 in conversation