BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mateescu
Fluorite | Level 6

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;

mateescu_0-1703891292008.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

2 REPLIES 2
Ksharp
Super User
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;
mateescu
Fluorite | Level 6

Perfect, thank you!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 630 views
  • 2 likes
  • 2 in conversation