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!

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