BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
G-Scott
Fluorite | Level 6
Hi All,

So I am using proc means to generate some stats on two variable, let’s say TimeFromEventA and TimeFromEventB for a group of individuals by race/ethnicity.

So, the issue I am running into is I would like lines for all of the class options, even if there are no observations.

For example:

Proc Means data=have;
Var TimeFromEventA TimeFromEventB;
Class raceeth;
Run;

If I don’t have any observations in my data set where raceeth=3…it is not included in the output, and I would like it to be. Any way to make this possible?
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

So you have to have a method to add values that are not present in the data set.

One of the ways is to use a FORMAT to provide the values and a PRELOADFMT option and COMPLETETYPES in Proc Means/Summary:

An example:

Proc format;
value $newgender
'F'='Female'
'M'='Male'
'X'='Other'
;

proc means data=sashelp.class completetypes;
   class sex/preloadfmt;
   format sex $newgender.;
   var height weight;
run;

The format provides a formatted value for a variable expecting values of F, M and X. The SASHELP.CLASS data set has values of F and M for the Sex variable. The Preloadfmt works with Completetypes to accomplish the values that don't appear in the actual data.

 

View solution in original post

4 REPLIES 4
ballardw
Super User

So you have to have a method to add values that are not present in the data set.

One of the ways is to use a FORMAT to provide the values and a PRELOADFMT option and COMPLETETYPES in Proc Means/Summary:

An example:

Proc format;
value $newgender
'F'='Female'
'M'='Male'
'X'='Other'
;

proc means data=sashelp.class completetypes;
   class sex/preloadfmt;
   format sex $newgender.;
   var height weight;
run;

The format provides a formatted value for a variable expecting values of F, M and X. The SASHELP.CLASS data set has values of F and M for the Sex variable. The Preloadfmt works with Completetypes to accomplish the values that don't appear in the actual data.

 

Ksharp
Super User
/*
Or try CLASSDATA= option.
*/
data have;
 set sashelp.class;
run;

proc sql;
create table levels as
select distinct sex from have
union
select 'X' from have(obs=1)
union
select 'Y' from have(obs=1)
union
select 'Z' from have(obs=1)
;
quit;

proc means data=have classdata=levels ;
   class sex ;
   var height weight;
run;
PaigeMiller
Diamond | Level 26

@Ksharp wrote:
/*
Or try CLASSDATA= option.
*/

proc means data=have classdata=levels ;
   class sex ;
   var height weight;
run;

After all these years of using PROC MEANS/PROC SUMMARY on a daily basis at work, and trying to explain PROC MEANS/PROC SUMMARY to total strangers while I am on vacation, I still learn something new from this forum. Thanks, @Ksharp 

--
Paige Miller
G-Scott
Fluorite | Level 6
I would also note that this also worked. Thank you!

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
  • 4 replies
  • 443 views
  • 11 likes
  • 4 in conversation