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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.