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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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