I have a large set with several variables, some records have missing data for some of the variables. I am trying to generate a histogram (by group) but I get an extra histogram for the missing data (missing data in the group variable). Here is a small example code of what I have. I want to know if there is any way to ignore the missing data in the Group.
Thanks,
data test;
input Var1 Group;
cards;
1 1
2 1
3 1
3 .
4 .
5 .
2 2
3 2
4 2
5 2
;
run;
title height=16pt "Var by Group";
proc sgplot data=test ;
histogram Var1 / group=Group transparency=0.5 datalabelattrs=(size=16) ;
density Var1 / type=kernel group=Group;
keylegend /location=outside position=topright valueattrs=(size=14);
xaxis display=(noline) labelattrs=(size=16) valueattrs=(size=16) ;
yaxis display=(noline) labelattrs=(size=16) valueattrs=(size=16);
run;
quit;
title height=16pt "Var by Group"; proc sgplot data=test ; where Group is not missing; histogram Var1 / group=Group transparency=0.5 datalabelattrs=(size=16) ; density Var1 / type=kernel group=Group ; keylegend /location=outside position=topright valueattrs=(size=14); xaxis display=(noline) labelattrs=(size=16) valueattrs=(size=16) ; yaxis display=(noline) labelattrs=(size=16) valueattrs=(size=16); run; quit;
title height=16pt "Var by Group"; proc sgplot data=test ; where Group is not missing; histogram Var1 / group=Group transparency=0.5 datalabelattrs=(size=16) ; density Var1 / type=kernel group=Group ; keylegend /location=outside position=topright valueattrs=(size=14); xaxis display=(noline) labelattrs=(size=16) valueattrs=(size=16) ; yaxis display=(noline) labelattrs=(size=16) valueattrs=(size=16); run; quit;
Perfect, thank you!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.