BookmarkSubscribeRSS Feed
stan
Quartz | Level 8

I try to plot raw data points and mean bars with standard errors in one graph:

DATA long_added;

SET long_;

if GROUP = "AA" then AA = -0.955 + 0.05 * rannor(0);

if GROUP = "BB" then BB = 0.25 + 0.05 * rannor(0);

if GROUP = "CC" then CC = 1.5 + 0.05 * rannor(0);

if GROUP = "DD" then DD = 2.75 + 0.05 * rannor(0);

if GROUP = "EE" then EE = 4 + 0.05 * rannor(0);

RUN;

PROC SUMMARY DATA = long NWAY;

  CLASS my_class;

  VAR my_values;

  OUTPUT OUT = summary1 MEAN = MEAN STDERR = STDERR;

RUN;

PROC TEMPLATE;

  DEFINE STATGRAPH BarsWithSEMAndRawData;

  BEGINGRAPH;

  LAYOUT OVERLAY /

  YAXISOPTS = (GRIDDISPLAY = ON DISPLAY = (LABEL TICKS TICKVALUES)

       LINEAROPTS = (VIEWMIN = 0 THRESHOLDMAX = 1 ) OFFSETMIN = 0 OFFSETMAX = 0)

  X2AXISOPTS = (DISPLAY = (LINE) LINEAROPTS = (VIEWMIN = -1 VIEWMAX = 4));

  SCATTERPLOT X = AA Y = VALUEE / XAXIS = x2;

  SCATTERPLOT X = BB Y = VALUEE / XAXIS = x2;

  SCATTERPLOT X = CC Y = VALUEE / XAXIS = x2;

  SCATTERPLOT X = DD Y = VALUEE / XAXIS = x2;

  SCATTERPLOT X = EE Y = VALUEE / XAXIS = x2;

  BARCHARTPARM X = GROUP Y = MEAN / BARWIDTH = 0.5

        ERRORLOWER = EVAL(MEAN - STDERR)

        ERRORUPPER = EVAL(MEAN + STDERR)

       FILLATTRS = (COLOR = LightSteelBlue TRANSPARENCY = 0);

  ENDLAYOUT;

  ENDGRAPH;

  END;

RUN;

When I use the following string:

     PROC SGRENDER DATA = long_added TEMPLATE = 'BarsWithSEMAndRawData'; RUN;

only scatters (without labels, ticks, tickvalues) are produced (points.jpg) along with the following message in the SAS Log window:

"WARNING: The BARCHARTPARM statement will not be drawn because one

or more of the required arguments were not supplied.".

When I use the following code:

     PROC SGRENDER DATA = summary1 TEMPLATE = 'BarsWithSEMAndRawData'; RUN;

only mean bars and SEM are drawn (bars.jpg) and along with the following message (repeated 5 times) in the SAS Log window:

"WARNING: The SCATTERPLOT statement will not be drawn because one or

more of the required arguments were not supplied.".

How to display scatters and bars with SEM simultaneously in a single graph?

Thank you.


points.jpgbars.jpg
4 REPLIES 4
Jay54
Meteorite | Level 14

As you see, the SGRENDER procedure takes only one data set.  So, all the data columns needed for the barchartparm statement and all the scatterplot statements must be in one data set.  If the data sets have unique column names, a simple merge of the two data sets may work.  Jittering is supported in SAS 9.3.

stan
Quartz | Level 8

Happy New Year Smiley Happy

Indeed, the data sets have unique variable names. A common name I used to combine the data sets by different approaches:

DATA my_data_combined;

  MERGE data_set_1 data_set_2;

  BY GROUP;

RUN;

DATA my_data_combined;

  SET data_set_1 data_set_2;

  BY GROUP;

RUN;

DATA my_data_combined;

  SET data_set_1 data_set_2;

RUN;

But the same message in SAS Log window appeared the same:

WARNING: The data for a BARCHARTPARM statement are not appropriate.

         The BARCHARTPARM statement expects summarized data. The bar

         chart might not be drawn correctly.

I used the following piece of code for that statement:

BARCHARTPARM

  X = GROUP

  Y = MEAN /

    ERRORLOWER = EVAL(MEAN - STDERR)

    ERRORUPPER = EVAL(MEAN + STDERR);

The my_data_combined data set ( created with both SET and BY ) is in the attached file.

What it can be?

Jay54
Meteorite | Level 14

This is a different message from previous.  Previously, the BarChartParm and ScatterPlot were not drawn because some required variables were not provided.  Now, the BarChartParm is saying you have extra observations per category.

stan
Quartz | Level 8

If I'm not mistaken your comment is reasonable in the case of SET and SET-BY approaches when indeed there is one extra observation per category. But when I use MERGE-BY statements the message is the same. I.e. there are no extra records, but they are multiplied according to the number of observations in a category...

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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