Hi,
which code do I have to use to ask SaS 9.4 to display all categories of a variable in a table even though some categories have no observation?
(f.e.: variable 'gender' with the categories "female", "male", "divers", "optout", "missing") and no person used the category "optout").
I did manage to generate a format (gender.) so all categories are defined, but I havent found a solution where or how use the defined format (gender.) in a proc to display responses to ALL categories; (especially for the proc freq, proc print, proc tabulate - so really basic steps).
Thanks in advance.
JDS1
Procs Means/Summary, Report and Tabulate have an option PRELOADFMT that will report on categories of class variables using the defined format.
proc tabulate data=yourdata; class gendervar / preloadfmt ; format gendervar gender. ; table gendervar, n /printmiss; run;
Each procedure that uses Preloadfmt has slight differences on how it must be used and there are some interactions between them. Proc Tabulate for example requires one of table Printmiss option, or Order=data Class statement option or use of a CLASSDATA data set. Using multiple of these the order of the data display may change.
Check each procedure for details.
Here is an example for PROC FREQ:
data have;
set sashelp.heart end=last;
w=1;output;
if last then do;w=0;sex='NA';output;end;
run;
proc freq data=have;
table sex;
weight w/zero;
run;
Hi, unfortunately this code (with w/zero in proc freq) didn't work out for my data.
Procs Means/Summary, Report and Tabulate have an option PRELOADFMT that will report on categories of class variables using the defined format.
proc tabulate data=yourdata; class gendervar / preloadfmt ; format gendervar gender. ; table gendervar, n /printmiss; run;
Each procedure that uses Preloadfmt has slight differences on how it must be used and there are some interactions between them. Proc Tabulate for example requires one of table Printmiss option, or Order=data Class statement option or use of a CLASSDATA data set. Using multiple of these the order of the data display may change.
Check each procedure for details.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.