This sample uses PROC PLOT to create a line plot that displays a reference line at the mean value of each BY group. This sample code is the code from the PLOTREF.SAS program in the SAS® sample library.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/****************************************************************/
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: PLOTREF */
/* TITLE: Plot with Reference Line at Mean of Each by Group */
/* PRODUCT: SAS */
/* SYSTEM: ALL */
/* KEYS: MACRO, AVERAGE, REFERENCE LINE */
/* PROCS: MEANS PLOT PRINT */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: */
/* MISC: */
/* */
/****************************************************************/
DATA EMPLOY;
INPUT SEX $ AGE SALARY;
CARDS;
F 21 17000
F 18 10500
F 32 27000
M 19 10900
M 33 31000
M 23 21000
M 24 21000
;
PROC MEANS;
VAR SALARY;
OUTPUT OUT=MEAN N=TOTAL MEAN=MSAL;
BY SEX;
RUN;
PROC PRINT;
RUN;
TITLE 'SALARY * AGE' ;
DATA FORPLOTS;
SET MEAN END=EOF;
LENGTH NCNT $3;
RETAIN FIRSTOBS 1;
OBS+TOTAL;
CNT+1;
NCNT=LEFT(CNT);
CALL SYMPUT('FIRST'||NCNT,FIRSTOBS);
CALL SYMPUT('LAST'||NCNT,OBS);
CALL SYMPUT('REF'||NCNT,MSAL);
FIRSTOBS+OBS;
IF EOF THEN CALL SYMPUT('TOTAL',CNT);
RUN;
%MACRO PLOTIT;
%DO I=1 %TO &TOTAL;
PROC PLOT DATA=EMPLOY(FIRSTOBS=&&FIRST&I OBS=&&LAST&I);
PLOT AGE*SALARY/HREF=&&REF&I;
%END;
%MEND;
%PLOTIT
RUN;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
SEX=F The MEANS Procedure Analysis Variable : SALARY N Mean Std Dev Minimum Maximum ----------------------------------------------------------------- 3 18166.67 8311.64 10500.00 27000.00 ----------------------------------------------------------------- SEX=M Analysis Variable : SALARY N Mean Std Dev Minimum Maximum ----------------------------------------------------------------- 4 20975.00 8205.84 10900.00 31000.00 ----------------------------------------------------------------- OBS SEX _TYPE_ _FREQ_ TOTAL MSAL 1 F 0 3 3 18166.67 2 M 0 4 4 20975.00 SALARY * AGE Plot of AGE*SALARY. Legend: A = 1 obs, B = 2 obs, etc. AGE | | 35 + | | | | | | | | | A | | | | 30 + | | | | | | | | | | | | | 25 + | | | | | | | | | | | | A | 20 + | | | | | | A | | | | | | | 15 + | ---+---------+---------+---------+---------+---------+---------+---------+-- 10000 12500 15000 17500 20000 22500 25000 27500 SALARY SALARY * AGE Plot of AGE*SALARY. Legend: A = 1 obs, B = 2 obs, etc. AGE | | 33 + | A | | 32 + | | | 31 + | | | 30 + | | | 29 + | | | 28 + | | | 27 + | | | 26 + | | | 25 + | | | 24 + A | | 23 + A | | 22 + | | | 21 + | | | 20 + | | | 19 + A | ---+-------------+-------------+-------------+-------------+-------------+-- 10000 15000 20000 25000 30000 35000 SALARY
Type: | Sample |
Topic: | Analytics ==> Descriptive Statistics SAS Reference ==> Procedures ==> PLOT SAS Reference ==> Procedures ==> MEANS |
Date Modified: | 2019-06-06 09:48:46 |
Date Created: | 2005-05-23 13:52:39 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | All | n/a | n/a |