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: Call for Content

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!

Submit your idea!

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
  • 774 views
  • 2 likes
  • 3 in conversation