BookmarkSubscribeRSS Feed
Magdal3na
Fluorite | Level 6

Hello,

this problem is troubling my mind:

I'm creating graphs via sgplot, a histogram with two groups (0&1) displayed in one graph.  It works fine, as long as I don't use labels I made via proc template for my group variable. Then one group just disappears. Depending on how I sort my group variable, only the 'yes' or 'no' group is displayed. It's still the same data and the same group variable I put into the graph, it just got a label now. The labels work perfectly fine on different other procs like proc mean.

In the log there is no error message.

There are several scenarios I performed, the problem seems to lie with the histogram, group and label statement. I created dummy data and I experience the same problem there. If the group varibale is a string (yes/no) both groups are displayed. If I use a different graph kind in sgplot, both groups are displayed even if labeld.

My Sas Version is 9.4 (TS1M2)

Below I insert my code, the graphs and in the attachment you can find the dummy data. Anybody got ideas how to solve this? (Other then transforming the group variable into a string)

 

 

*Graph without labeled group variable;proc sort data=test; by anaemia; run;
proc sgplot data=test;
histogram Hb / GROUP=anaemia transparency=0.5;
density Hb / GROUP=anaemia;run;

*Creating format; proc format; value yn 0='No' 1='Yes'; run; data test2; set test; format anaemia yn.; run; *Labels work; proc freq data=test2; table anaemia; run; *Creating same graph again, only one group is displayed; proc sort data=test2; by anaemia; run; proc sgplot data=test2; histogram Hb / GROUP=anaemia transparency=0.5; density Hb / GROUP=anaemia; run;

 

SGPlot2.png

SGPlot1.png

 

3 REPLIES 3
Rick_SAS
SAS Super FREQ

This works correctly on my version of SAS 9.4M6. What version of SAS are you running?

 

By the way, you don't need to create the TEST2 data set. Just add the FORMAT statement to PROC SGPLOT:

 

proc sgplot data=test;
   format anaemia yn.;
   histogram Hb / GROUP=anaemia transparency=0.5;
   density Hb / GROUP=anaemia;
run;

 

Magdal3na
Fluorite | Level 6

This problem seems to be version related, I use SAS base, Version 9.4 (TS1M2). Is this a bug I better should report?

Normally I add the format to the exísting data set, just wanted to create a new one for demonstration purpose. Good to know that I can add the format statement in the proc sgplot, didn't know that yet.

Thanks for your help!

Rick_SAS
SAS Super FREQ

Since the problem has been fixed, I don't think you need to report it. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1372 views
  • 0 likes
  • 2 in conversation