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.

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
  • 3 replies
  • 1633 views
  • 1 like
  • 2 in conversation