BookmarkSubscribeRSS Feed
BAGaucho
Obsidian | Level 7

Hi,

 

I love to use SGPLOT and find something new useful option every time I use SGPLOT. Recently, I noticed that I can use STAT= option at XAXISTABLE statement. This is great option. However, when I use STAT=FREQ option, the frequency is all observation instead of only non-missing observation. Is there any way to remove missing cases? So, if the there isn't any non-missing values in a group, I love to put zero instead of blank and also show only non-missing N. Here is my code.

 

proc sgplot data=PD nocycleattrs noborder noautolegend;
   refline -100 to 200 by 50 / axis = y transparency=0.9;
   vbar period / response=PDvalue stat=mean dataskin=pressed fillattrs=(color=green)
                        baselineattrs=(thickness=0) limitstat=stderr barwidth=0.4;

   xaxis display=(noticks nolabel);
   yaxis display=(noticks) ranges=(-100 - 300) label='Mean % PD Value Change' ;
   xaxistable period    / stat=freq label='N=' location=inside;
   xaxistable PDvalue / stat=mean label='MEAN=' location=inside;
run;

 

The MEAN values of PDvalue are ok since ignoring missing values when we create MEAN. However, the freq values are not non-missing N. I can just drop all missing values before I run this procedure, but I like to indicate PERIOD value even if all PD values are missing.

 

Thank in advance,

 

Raymond

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

I can't see your data, so needless to say the code below is unstested. However, I think the three options highlighted will give you what you want. I added a Group= option to your VBAR Statement and two options to your xaxistable statement

 

proc sgplot data=PD nocycleattrs noborder noautolegend;
   refline -100 to 200 by 50 / axis = y transparency=0.9;
   vbar period / response=PDvalue stat=mean dataskin=pressed fillattrs=(color=green)
                        baselineattrs=(thickness=0) limitstat=stderr barwidth=0.4
                        group=period;                                      /* New Option */

   xaxis display=(noticks nolabel);
   yaxis display=(noticks) ranges=(-100 - 300) label='Mean % PD Value Change' ;
   xaxistable period    / stat=freq label='N=' location=inside
                          nomissingclass classdisplay=cluster; /* New options */
   xaxistable PDvalue / stat=mean label='MEAN=' location=inside;
run;

 

 

BAGaucho
Obsidian | Level 7

Thanks for your quick reply, draycut!

 

After I posted, I thought about what I did and found my own mistake. I asked for frequency of each period so obviously SAS will provide all observation count per period no matter what the y-axis values are missing or not. Stupid of me.

 

So, I specified PDvalue instead of period, but format issue exists since I specified a format for PDvalue. Well, I decided to use very old trick which creating a new count variable as CNT (=1 if non missing) and use CNT to calculate frequency.  Yes, works fine.

 

I know, I should thought about twice before I posted this. I will be extra careful next time.

 

Thanks,

 

Raymond

PeterClemmensen
Tourmaline | Level 20

Be aware though that the NOMISSINGCLASS Option is supported only is SAS 9.4M3 and later.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2339 views
  • 1 like
  • 2 in conversation