BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JDS1
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

5 REPLIES 5
Ksharp
Super User

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;

Ksharp_0-1687443140829.png

 

JDS1
Calcite | Level 5
Thanks! I will try out the w/zero option as well!
JDS1
Calcite | Level 5

Hi, unfortunately this code (with w/zero in proc freq) didn't work out for my data.

ballardw
Super User

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.

 

JDS1
Calcite | Level 5
Thank you so much! It worked

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 891 views
  • 2 likes
  • 3 in conversation