Hello, I have a code that was handled to me and I'm reviewing, I did not wrote the code. I encontared several error in the following code, I am new to this function and can't figure out what is the fix, I would very much appreciate your help
proc sgplot data = seg_tmp.all_v2;
format MNTH_SMRY_START_DT dtmonyy.
styleattrs
datacolors=(VIGB VLIGB orange)
DATACONTRASTCOLORS = (orange blue black);
vline MNTH_SMRY_START_DT / response=tot_trans_am grouporder=data stat=mean lineattrs=(thickness=2 PATTERN =solid);
vline MNTH_SMRY_START_DT / response=tot_trans_am grouporder=data stat=median y2axis lineattrs=(thickness=2 PATTERN =solid);
label MNTH_SMRY_START_DT = 'Month';
y2axis label='Median Transaction Amount';
yaxis label = 'Mean Transaction Amount';
xaxis label = 'Month';
by seg;
run;
And the error are as follows:
proc sgplot data = seg_tmp.all_v2;
format MNTH_SMRY_START_DT dtmonyy.
styleattrs
datacolors=(VIGB VLIGB orange)
- -
22 22
200 200
DATACONTRASTCOLORS = (orange blue black);
-
22
200
WARNING: Variable STYLEATTRS not found in data set SEG_TMP.ALL_V2.
WARNING: Variable DATACOLORS not found in data set SEG_TMP.ALL_V2.
WARNING: Variable VIGB not found in data set SEG_TMP.ALL_V2.
WARNING: Variable VLIGB not found in data set SEG_TMP.ALL_V2.
WARNING: Variable ORANGE not found in data set SEG_TMP.ALL_V2.
WARNING: Variable ORANGE not found in data set SEG_TMP.ALL_V2.
WARNING: Variable BLUE not found in data set SEG_TMP.ALL_V2.
WARNING: Variable BLACK not found in data set SEG_TMP.ALL_V2.
ERROR 22-322: Syntax error, expecting one of the following: a name, a format name, ;, -, :, _ALL_, _CHARACTER_, _CHAR_,
_NUMERIC_.
ERROR 200-322: The symbol is not recognized and will be ignored.
vline MNTH_SMRY_START_DT / response=tot_trans_am grouporder=data stat=mean lineattrs=(thickness=2 PATTERN
! =solid);
vline MNTH_SMRY_START_DT / response=tot_trans_am grouporder=data stat=median y2axis lineattrs=(thickness=2
------
22
76
! PATTERN =solid);
ERROR 22-322: Syntax error, expecting one of the following: FREQ, MEAN, SUM.
ERROR 76-322: Syntax error, statement will be ignored.
label MNTH_SMRY_START_DT = 'Month';
y2axis label='Median Transaction Amount';
yaxis label = 'Mean Transaction Amount';
xaxis label = 'Month';
by seg;
run;
I believe the code was written with a recent version of SAS and you are running it on an older version. The error that says
ERROR 22-322: Syntax error, expecting one of the following: FREQ, MEAN, SUM.
indicates that STAT=MEDIAN is not support on your version of SAS.
I think the DATACOLORS= option was added in SAS 9.4M3.
The STAT=MEDIAN option is relatively new...maybe SAS 9.4M5.
Also
proc sgplot data = seg_tmp.all_v2;
format MNTH_SMRY_START_DT dtmonyy. <= no ; for format statement so styleattrs is treated as the next variable to apply a format to
styleattrs
datacolors=(VIGB VLIGB orange)
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.