BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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;
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
deleted_user
Not applicable
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
Cynthia_sas
SAS Super FREQ
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
AAdams
Calcite | Level 5
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?
data_null__
Jade | Level 19
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]
deleted_user
Not applicable
Thanks so much. I'll explore these different approaches.
Ksharp
Super User
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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2383 views
  • 0 likes
  • 6 in conversation