BookmarkSubscribeRSS Feed
tipscode
Obsidian | Level 7

In SAS 9.4 I have a dataset where there are US states with missing data for all variables and would like to have those states to still show up in proc tabulate.

 

I was considering making an empty dataset with simply all 52 states, along with a dummy variable default to 0, and merge this dataset with the existing dataset to do this.

 

Thank you in advance for any suggestions.

2 REPLIES 2
ballardw
Super User

Generally with Proc Tabulate the approach for this is to use the option Preloadfmt for the class variable. This does require that you have a format for the variable with all of the levels you want displayed. Then add the Printmiss option to the table options or use order=data for the class variable.

 

Here is a very trivial example:

proc format library=work;
value $a
'A' = 'Apple'
'B' = 'Banana'
'C' = 'Cat'
'D' = 'Dog'
;
run;

data tab;
   do grp = 'A','C','D';
     i+1;
     output;
   end;
run;


proc tabulate data= tab;
   class grp/ preloadfmt;
   format grp $a.;
   var i;
   table grp,
         i *(n mean)
         / printmiss;
run;

Note that if you use a multilabel format then the order of statements in the format definition and the options order= will seriously effect the appearance.

 

tipscode
Obsidian | Level 7

Thank you.

 

In the end, I created a format for the 52 US states and applied them to the proc tabulate like so:

 

         

 PROC TABULATE NOSEPS MISSING FORMAT=7. DATA=tbls;
 CLASS STATEFIP /PRELOADFMT;
 CLASS SERVICES YR;
 TABLES YR, STATEFIP, SERVICES / PRINTMISS MISSTEXT='0';
 WHERE YR = &SAMPLEYR1;
 FORMAT SERVICES SVC. STATEFIP $STATE.;
 RUN;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 1338 views
  • 1 like
  • 2 in conversation