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.
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.
/*
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;
@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
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.
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.
Ready to level-up your skills? Choose your own adventure.