Hi,
I'm new to using charts in sas. I want to have a line chart and a table below the chart. I used code from the following reference from the link: https://support.sas.com/kb/49/697.html but instead of using a bar chart. I want to use a line chart so that each value for one of the variables ("Slept") is graph.
Can i replace "barchart" with something else to make this into a line graph? Thanks in advance for your thoughts and suggestions.
DATA Slept; INPUT QUARTER SLEPT PERCENT C_Count; DATALINES; 2019Q1 NA 5 6 2019Q2 NO 2 3 2019Q3 UKNOWN 6 8 2019Q4 YES 5 7 2020Q1 NA 5 6 2020Q2 NO 9 11 2020Q3 UKNOWN 5 6 2020Q4 YES 5 7 2019Q1 NA 0 2019Q2 NO 17 2019Q3 UKNOWN 0 2019Q4 YES 83 2020Q1 NA 0 2020Q2 NO 14 2020Q3 UKNOWN 14 2020Q4 YES 71 2019Q1 NA 0 2019Q2 NO 100 2019Q3 UKNOWN 0 2019Q4 YES 0 2020Q1 NA 0 2020Q2 NO 0 2020Q3 UKNOWN 0 2020Q4 YES 100 2019Q1 NA 0 2019Q2 NO 0 2019Q3 UKNOWN 0 2019Q4 YES 100 2020Q1 NA 0 2020Q2 NO 0 2020Q3 UKNOWN 0 2020Q4 YES 100 ; RUN; proc template; define statgraph GRAPHY; begingraph; entrytitle 'SLEPT '; layout lattice / rowweights=(.65 .35); layout overlay; barchart X=Quarter y=percent / group=SLEPT barlabel=true dataskin=gloss; endlayout; layout overlay / xaxisopts=(type=discrete label='Number per CY Quarter' display=(label)) walldisplay=none; blockplot x=Quarter block=C_Count / class=Quarter display=(outline values label) repeatedvalues=true; endlayout; endlayout; endgraph; end; run; proc sgrender data=SLEPT template=GRAPHY; run;
Okay, i think i figured it out. The below worked for me.
@ DAN Thanks again for your help.
proc template;
define statgraph GRAPHY;
begingraph;
entrytitle 'SLEPT ';
layout lattice / rowweights=(.65 .35);
layout overlay;
SERIESPLOT x=Quarter y=percent / group=SLEPT datalabel=percent
display =all
lineattrs = (thickness = 3 pattern=solid)
markerattrs=( symbol= circlefilled size=9 color= black) datalabelattrs=percent (size=8) name='b';
discretelegend 'b'/location=outside
across =4
autoalign =auto
exclude =(" " ".");
endlayout;
layout overlay / xaxisopts=(type=discrete label='CY Quarter'
display=(label)) walldisplay=none;
blockplot x=Quarter block=C_Count / class=Quarter display=(outline values label)
repeatedvalues=true;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=SLEPT template=GRAPHY;
run;
GTL supports a LINECHART statement. That should do what you want.
Hi Dan, Thanks for your response. It seems to work after i replaced "barchart" with "SERIESPLOT". However, I can't seem to get the labels and keylegend to show. Any suggestions or ideas?
proc template;
define statgraph GRAPHY;
begingraph;
entrytitle 'slept ';
layout lattice / rowweights=(.65 .35);
layout overlay;
SERIESPLOT x=Quarter y=percent / group=slept
lineattrs = (thickness = 3 pattern=solid)
markerattrs=( symbol= circlefilled size=9 color= white) datalabelattrs=(label (size=8)) name='b';
discretelegend 'b'/location=inside
across =1
autoalign =auto
exclude =(" " ".");
endlayout;
layout overlay / xaxisopts=(type=discrete label='Number per CY Quarter'
display=(label)) walldisplay=none;
blockplot x=Quarter block=C_Count / class=Quarter display=(outline values label)
repeatedvalues=true;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=slept template=GRAPHY;
run;
Add the following option to the SERIESPLOT to get your curve labels:
curvelabel=slept
Are you saying you're not getting.a legend?
Thanks Dan!!
I added the the suggestion but put "percent" instead of "slept" because i wanted the percentage to show. The legend appears now but not all of the labels for "Percent" appears. Below is the sas code with some changes.
proc template;
define statgraph GRAPHY;
begingraph;
entrytitle 'slept ';
layout lattice / rowweights=(.65 .35);
layout overlay;
SERIESPLOT x=Quarter y=percent / group=slept curvelabel=percent
lineattrs = (thickness = 3 pattern=solid)
markerattrs=( symbol= circlefilled size=9 color= white) datalabelattrs=label (size=8)name='b';
discretelegend 'b'/location=inside
across =1
autoalign =auto
exclude =(" " ".");
endlayout;
layout overlay / xaxisopts=(type=discrete label='Number per CY Quarter'
display=(label)) walldisplay=none;
blockplot x=Quarter block=C_Count / class=Quarter display=(outline values label)
repeatedvalues=true;
endlayout;
endlayout;
endgraph;
end;
run;
Okay, i think i figured it out. The below worked for me.
@ DAN Thanks again for your help.
proc template;
define statgraph GRAPHY;
begingraph;
entrytitle 'SLEPT ';
layout lattice / rowweights=(.65 .35);
layout overlay;
SERIESPLOT x=Quarter y=percent / group=SLEPT datalabel=percent
display =all
lineattrs = (thickness = 3 pattern=solid)
markerattrs=( symbol= circlefilled size=9 color= black) datalabelattrs=percent (size=8) name='b';
discretelegend 'b'/location=outside
across =4
autoalign =auto
exclude =(" " ".");
endlayout;
layout overlay / xaxisopts=(type=discrete label='CY Quarter'
display=(label)) walldisplay=none;
blockplot x=Quarter block=C_Count / class=Quarter display=(outline values label)
repeatedvalues=true;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=SLEPT template=GRAPHY;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.