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;

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