BookmarkSubscribeRSS Feed
tburus
Obsidian | Level 7

I am creating a cross tabulation table in PROC REPORT and have a couple of columns where there is no data for the cross tab (generated as ANALYSIS variables). As coded it currently displays blanks in these cells. I want to replace it with 0 (or 0% as appropriate). I tried OPTIONS MISSING='0', but this just places a 0, and doesn't match the formatting of all cells.

Code:

proc report data=mfb_ly nowd center;
	where(not missing(mech) and not missing(diag));
	options missing='';
	column mech diag,(nationalweight nationalweight=pct);
	define mech / group 'Activity' center order=freq descending style(column)=[just=l];
	define diag / across 'Diagnosis' order=formatted;
	define nationalweight / analysis SUM 'n' format=comma8.0;
	define pct / analysis PCTSUM format=percent8.0 '%';
	rbreak after /summarize UL OL style(summary)={font_weight=bold};
	compute mech;
    	if _break_ = '_RBREAK_' then mech = 'Total';
	endcomp;
run;

Result:

cross_tab.png

 

1 REPLY 1
mkeintz
PROC Star

I suspect you can make a custom format that uses the regular sas formats you specify, with one wrinkle - format a missing value to a 0, as in:

 

proc format;
  value mycom
      .=0  other=[comma8.0] ;
  value mypct
      .=0  other=[percent8.0];
run;

  followed by a modification of the proc report:

 

proc report data=mfb_ly nowd center;
	where(not missing(mech) and not missing(diag));
	options missing='';
	column mech diag,(nationalweight nationalweight=pct);
	define mech / group 'Activity' center order=freq descending style(column)=[just=l];
	define diag / across 'Diagnosis' order=formatted;

	define nationalweight / analysis SUM 'n' format=mycom8.0;
	define pct / analysis PCTSUM format=mypct8.0 '%';

	rbreak after /summarize UL OL style(summary)={font_weight=bold};
	compute mech;
    	if _break_ = '_RBREAK_' then mech = 'Total';
	endcomp;
run;

 

 

 

 

 

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 2245 views
  • 2 likes
  • 2 in conversation