Help using Base SAS procedures

Display variable with zero frequency in one-way frequency

Reply
N/A
Posts: 0

Display variable with zero frequency in one-way frequency

Can anyone help me? I am running one-way frequency tables on a list of variables that have 3 possible levels. I want all 3 levels displayed even when there are no responses for a given level (i.e. for some vars, nobody replied 'never'). I thought the sparse option in the tables statement would work, but it did not. Any ideas? Thank you!

format never 0='never' 1='sometimes' 2='always';

proc freq data=mydata;
tables var1--var10/sparse;
format var10--var10 never.;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: Display variable with zero frequency in one-way frequency

From the code you shared, the PROC FORMAT is not coded correctly, to generate the SAS numeric format NEVER. Also, consider the MISSING operand on the TABLES statement, as well.

Scott Barry
SBBWorks, Inc.

SAS DOC on PROC FREQ - link below:

http://support.sas.com/documentation/cdl/en/procstat/59629/HTML/default/freq_toc.htm
N/A
Posts: 0

Re: Display variable with zero frequency in one-way frequency

Thanks for answering and oops Right - my mistake on the format statement.... But that's not the problem. And using the 'missing' option shows the cases with missing data, but that's not what I want either. It's really just in the table...I want the table to display a line for 'Never' even though there are no responses with that value.
Freq Percent
Never 0 0
Sometimes 10 50
Always 10 50
SAS Super FREQ
Posts: 8,744

Re: Display variable with zero frequency in one-way frequency

Hi:
PROC MEANS, PROC REPORT and PROC TABULATE all support the use of the PRELOADFMT option that allows you to specify a user-defined format to provide ALL
the -possible- values that you want to see in your report (even if, as in your case, there are no values of 0 in the actual data) and so some of the formatted values will show as 0.

However, PRELOADFMT does not work with PROC FREQ. If you look at examples of PRELOADFMT with either PROC TABULATE or PROC REPORT, you'll probably find an example that will work for you.

cynthia
Occasional Contributor
Posts: 7

Re: Display variable with zero frequency in one-way frequency

I am having the same problem, however I am using PROC FREQ for the one way chi sq test, not just reporting. I have a expected proportion that, in the data, is not represented. My code is:

proc freq data = otptClinic;
tables Race / testp = (.59 .01 .08 .01 .31);
run;

These are the expected proportions of race in our outpatient clinic (Afr.Am, Nat.Am, Latino, Other, White). I am testing a subset of the data to see if there is any disparity of race in this subset. The subset contains 0 native American persons. I'd like this information included in the chi sq goodness of fit test (and not combine it with another group). However, I get an error when running this code, because the data only has 4 categories.

I am, at best, an average SAS user, but I thought PROC FREQ was my only option for the one way chi sq (and it does not appear that either PROC TABULATE or PROC REPORT have a chi sq option).

Is there a way to do this, or would I be stuck with combining categories?
Respected Advisor
Posts: 3,777

Re: Display variable with zero frequency in one-way frequency

Condsider this example.

[pre]
data otpt;
input race:$8. freq;
cards;
Afr.Am 10
Nat.Am 0
Latino 12
Other 2
White 9
;;;;;
run;
proc freq data = otpt;
tables Race / testp = (.59 .01 .08 .01 .31);
weight freq / zeros;
run;
[/pre]
N/A
Posts: 0

Re: Display variable with zero frequency in one-way frequency

Thanks so much. I'll explore these different approaches.
Super User
Posts: 9,687

Re: Display variable with zero frequency in one-way frequency

Hi.
Cynthia@sas is right, you can use proc tabulate or report to get that.
This is an example.


[pre]
proc format;
value $sexfmt
'F'='Female'
'M'='Male'
'U'='Unknow'
;
run;

proc report data=sashelp.class nowd completerows;
column sex n;
define sex /group format=$sexfmt. preloadfmt exclusive;
define n /format=4. 'Freq';
run;

[/pre]



Ksharp
Ask a Question
Discussion stats
  • 7 replies
  • 287 views
  • 0 likes
  • 6 in conversation