I am trying to use PROC SGPLOT
with the following dataset. Currently with my script the x-axis goes from 1-52. I want the x-axis to start with week 35 and continue through week 52, then follow with weeks 1 to 34. Any assistance would be greatly appreciated.
data original_data;
infile datalines dlm="," dsd;
input Surveillance_Week $ weekly_count_curryr rolling_avg_prevyr;
datalines;
35,15,7
36,11,5.7
37,,8.3
38,,9.7
39,,13.7
40,,15.3
41,,20
42,,24
43,,27
44,,27.7
45,,29.7
46,,32
47,,33
48,,30
49,,27.7
50,,24
51,,21
52,,15.3
53,,9.7
01,,13.7
02,,20
03,,18
04,,17
05,,14.3
06,,15.7
07,,14.7
08,,12.3
09,,10.7
10,,9.3
11,,11
12,,10.7
13,,10.3
14,,10.7
15,,11.3
16,,13.3
17,,13
18,,12.3
19,,9.7
20,,7.7
21,,7.3
22,,8.7
23,,7.3
24,,9
25,,8.7
26,,11.7
27,,10
28,,7.7
29,,5.3
30,,4.3
31,,6
32,,8.3
33,,7.3
34,,5.3
;
run;
proc sgplot data=comb_adjusted;
where serial_num >= 3;
vbar adjusted_week / response=weekly_count_curryr
datalabel
barwidth=0.8
fillattrs=(color=green);
vline adjusted_week / response=rolling_avg_prevyr
lineattrs=(color=blue thickness=3);
xaxis label="Surveillance Week"; /* No grid option here removes vertical lines */
yaxis label="count" grid; /* Keeps horizontal grid lines */
keylegend / position=topright across=1;
run;
You'd better post a desired graphic to let me know what you are looking for .
data original_data;
infile datalines dlm="," dsd;
input Surveillance_Week $ weekly_count_curryr rolling_avg_prevyr;
datalines;
35,15,7
36,11,5.7
37,,8.3
38,,9.7
39,,13.7
40,,15.3
41,,20
42,,24
43,,27
44,,27.7
45,,29.7
46,,32
47,,33
48,,30
49,,27.7
50,,24
51,,21
52,,15.3
53,,9.7
01,,13.7
02,,20
03,,18
04,,17
05,,14.3
06,,15.7
07,,14.7
08,,12.3
09,,10.7
10,,9.3
11,,11
12,,10.7
13,,10.3
14,,10.7
15,,11.3
16,,13.3
17,,13
18,,12.3
19,,9.7
20,,7.7
21,,7.3
22,,8.7
23,,7.3
24,,9
25,,8.7
26,,11.7
27,,10
28,,7.7
29,,5.3
30,,4.3
31,,6
32,,8.3
33,,7.3
34,,5.3
;
run;
proc sgplot data=original_data;
vbar Surveillance_Week / response=weekly_count_curryr
datalabel
barwidth=0.8
fillattrs=(color=green);
vline Surveillance_Week / response=rolling_avg_prevyr
lineattrs=(color=blue thickness=3);
xaxis label="Surveillance Week" type=discrete discreteorder=data; /* No grid option here removes vertical lines */
yaxis label="count" grid; /* Keeps horizontal grid lines */
keylegend / position=topright across=1;
run;
You'd better post a desired graphic to let me know what you are looking for .
data original_data;
infile datalines dlm="," dsd;
input Surveillance_Week $ weekly_count_curryr rolling_avg_prevyr;
datalines;
35,15,7
36,11,5.7
37,,8.3
38,,9.7
39,,13.7
40,,15.3
41,,20
42,,24
43,,27
44,,27.7
45,,29.7
46,,32
47,,33
48,,30
49,,27.7
50,,24
51,,21
52,,15.3
53,,9.7
01,,13.7
02,,20
03,,18
04,,17
05,,14.3
06,,15.7
07,,14.7
08,,12.3
09,,10.7
10,,9.3
11,,11
12,,10.7
13,,10.3
14,,10.7
15,,11.3
16,,13.3
17,,13
18,,12.3
19,,9.7
20,,7.7
21,,7.3
22,,8.7
23,,7.3
24,,9
25,,8.7
26,,11.7
27,,10
28,,7.7
29,,5.3
30,,4.3
31,,6
32,,8.3
33,,7.3
34,,5.3
;
run;
proc sgplot data=original_data;
vbar Surveillance_Week / response=weekly_count_curryr
datalabel
barwidth=0.8
fillattrs=(color=green);
vline Surveillance_Week / response=rolling_avg_prevyr
lineattrs=(color=blue thickness=3);
xaxis label="Surveillance Week" type=discrete discreteorder=data; /* No grid option here removes vertical lines */
yaxis label="count" grid; /* Keeps horizontal grid lines */
keylegend / position=topright across=1;
run;
@bijayadhikar wrote:
I am trying to use
PROC SGPLOT
with the following dataset. Currently with my script the x-axis goes from 1-52. I want the x-axis to start with week 35 and continue through week 52, then follow with weeks 1 to 34. Any assistance would be greatly appreciated.
data original_data;
infile datalines dlm="," dsd;
input Surveillance_Week $ weekly_count_curryr rolling_avg_prevyr;
datalines;
35,15,7
36,11,5.7
37,,8.3
38,,9.7
39,,13.7
40,,15.3
41,,20
42,,24
43,,27
44,,27.7
45,,29.7
46,,32
47,,33
48,,30
49,,27.7
50,,24
51,,21
52,,15.3
53,,9.7
01,,13.7
02,,20
03,,18
04,,17
05,,14.3
06,,15.7
07,,14.7
08,,12.3
09,,10.7
10,,9.3
11,,11
12,,10.7
13,,10.3
14,,10.7
15,,11.3
16,,13.3
17,,13
18,,12.3
19,,9.7
20,,7.7
21,,7.3
22,,8.7
23,,7.3
24,,9
25,,8.7
26,,11.7
27,,10
28,,7.7
29,,5.3
30,,4.3
31,,6
32,,8.3
33,,7.3
34,,5.3
;
run;proc sgplot data=comb_adjusted;
where serial_num >= 3;
vbar adjusted_week / response=weekly_count_curryr
datalabel
barwidth=0.8
fillattrs=(color=green);
vline adjusted_week / response=rolling_avg_prevyr
lineattrs=(color=blue thickness=3);
xaxis label="Surveillance Week"; /* No grid option here removes vertical lines */
yaxis label="count" grid; /* Keeps horizontal grid lines */
keylegend / position=topright across=1;
run;
Note that if you use a date value, such as the first day of the week, instead of an arbitrary number (1 - 52), that DATES will sort properly.
Something along these lines:
data original_data; infile datalines dlm="," dsd; input Surveillance_Week $ weekly_count_curryr rolling_avg_prevyr; if Surveillance_Week in (35:53) then weekdate = intnx('week','01JAN2022'd,Surveillance_Week-1); else weekdate =intnx('week','01JAN2023'd,Surveillance_Week-1); format weekdate date9.; datalines; 35,15,7 36,11,5.7 37,,8.3 38,,9.7 39,,13.7 40,,15.3 41,,20 42,,24 43,,27 44,,27.7 45,,29.7 46,,32 47,,33 48,,30 49,,27.7 50,,24 51,,21 52,,15.3 53,,9.7 01,,13.7 02,,20 03,,18 04,,17 05,,14.3 06,,15.7 07,,14.7 08,,12.3 09,,10.7 10,,9.3 11,,11 12,,10.7 13,,10.3 14,,10.7 15,,11.3 16,,13.3 17,,13 18,,12.3 19,,9.7 20,,7.7 21,,7.3 22,,8.7 23,,7.3 24,,9 25,,8.7 26,,11.7 27,,10 28,,7.7 29,,5.3 30,,4.3 31,,6 32,,8.3 33,,7.3 34,,5.3 ; run; proc sgplot data=original_data; vbar weekdate / response=weekly_count_curryr datalabel barwidth=0.8 fillattrs=(color=green) ; vline weekdate / response=rolling_avg_prevyr lineattrs=(color=blue thickness=3); xaxis label="Surveillance Week" values= ('21AUG2022'd to '20AUG2023'd by week) valuesrotate=vertical ; yaxis label="count" grid; /* Keeps horizontal grid lines */ keylegend / position=topright across=1; format weekdate yyweeku3.; run;
Note that it is not helpful to show a data set that does not match that used by the procedure. Your Original_data does not have have half the variables used in the plot which is using COMB_ADJUSTED
@ballardw thanks very much for providing some useful tips. Noted. Correct, I did not include all vars thinking may not be needed. All is good.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.