BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kashlik123
Obsidian | Level 7

I have a table with two group columns. One is a time variable and the other is just a group like the one below.

	Data have(drop=x);
	Do x = 1 to 6;
		year = 2010;
		group = 2;
		output;
	End;
	Do x = 1 to 6;
		year = 2020;
		group = ceil(x/3);
		output;
	End;
	Run;

I am attempting to calculate the share of observations by year and group in the following manner:

	Proc tabulate data=have out=not_want(drop=_type_ _page_ _table_);
	Class year / missing;
	Class group / missing;
	Table group='',year=''*colpctn='';
	Run;

The results window shows the desired results, however the output table does not contain the missing value from the year 2010. This is the expected output:

	Data want;
	year = 2010; group=1; share=100; output;
	year = 2010; group=2; share=.; output;
	year = 2020; group=1; share=50; output;
	year = 2020; group=2; share=50; output;
	Run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ok. You can use the Printmiss Option in the Table Statement like this. 

 

This will give you a 0 in the output pct, which is more correct than a missing value. 

 

Let me know if this works for you.

 

Proc tabulate data=have out=not_want(drop=_type_ _page_ _table_);
   Class year / missing;
   Class group / missing;
   Table group='',year=''*colpctn='' / printmiss;
Run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Is it a requirement to do this with Proc Tabulate?

kashlik123
Obsidian | Level 7

If there is another solution, which is just as compact and fast then sure, other option can be considered. For example doing this through PROC SQL takes too much time, as my real dataset is quite big.

PeterClemmensen
Tourmaline | Level 20

Ok. You can use the Printmiss Option in the Table Statement like this. 

 

This will give you a 0 in the output pct, which is more correct than a missing value. 

 

Let me know if this works for you.

 

Proc tabulate data=have out=not_want(drop=_type_ _page_ _table_);
   Class year / missing;
   Class group / missing;
   Table group='',year=''*colpctn='' / printmiss;
Run;

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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