2

I have this dataset:

data flu;
  input FluShotStatus age HealthAwareIndex gender;

  datalines;

  0    59    52    0
  0    61    55    1
  1    82    51    0
  0    51    70    0
  0    53    70    0
  0    62    49    1
  1    51    69    1
  0    70    54    1
  0    71    65    1
  0    55    58    1
  1    58    48    0
  0    53    58    1
  0    72    65    0
  1    56    68    0
  0    56    83    0
  0    81    68    0
  1    62    44    0
  ;
run;

I am trying to produce multiple, different plots from this dataset.

First, I want to produce a QQ Plot, using ODS, for the variable Health Awareness Index. I have used this code, which does what I want but I feel it could be better:

ods graphics on;
  proc univariate data=Measures;
      var Length Width;
      qqplot;
title ‘QQ Plot for Health Awareness Index’;
ods graphics off;
run;

Next I want to produce a Scatter Plot using ODS for Health Awareness Index and Age for Male subjects only. I have tried using:

ods graphics on;
proc sgscatter data=flu;
plot HealthAwareIndex*weight
run;
ods graphics off;

What I would like to know how to do and I just can't figure it is how would you produce separate histograms on one page? Ideally for males between Ages 50 and 70. Any hints or help would be gratefully appreciated.

Andrew Haynes
  • 2,612
  • 2
  • 20
  • 35
oxnot
  • 55
  • 5

1 Answers1

0

These can be created using sgplot and sgpanel :

1) Scatter plot (assuming that gender is 1 if male):

ods graphics on;
proc sgplot data = flu(where = (gender= 1));
  scatter x = age y=HealthAwareIndex;
run;
ods graphics off;

2) QQ plot

You can derive the values for a QQ-plot by using proc rank, then plotting them with scater in sgplot. To get a line for your QQ-plot, you can use proc sql to get the values of the scale and location parameters and then use these in the lineparm statement:

proc rank data=flu normal=blom out=haiQuant;
  var healthawareindex;
  ranks hai_Quant;
run;

** add line to plot;
proc sql;
  select mean(HealthAwareIndex), std(HealthAwareIndex)
  into :location, :scale
  from flu;
quit;

proc sgplot data=haiQuant;
  scatter x=hai_Quant y=HealthAwareIndex;
  xaxis label="Normal Quantiles";
  lineparm x = 0 y = &location slope = &scale;
run;

3) Histogram

To get multiple plots onto one page, you can use the sgpanel procedure which has similar syntax to sgplot. Use the panelby statement to alter the plots between panels, here's an example using FluShotStatus:

proc sort data = flu;
  by gender;
run;

proc sgpanel data = flu;
  panelby fss;
  vbox  HealthAwareIndex / category = gender;
run;

These all need to be made beautiful with titles, proper colours etc, but should be a good outline.

Andrew Haynes
  • 2,612
  • 2
  • 20
  • 35