Data visualization with SAS programming

proc sgpanel legend for group variable location=outside

Accepted Solution Solved
Reply
Super Contributor
Posts: 264
Accepted Solution

proc sgpanel legend for group variable location=outside

[ Edited ]

I have two major and few other minor problems in this plot. Major problems first. Each panel supposed to present line chart by 5 level of categorical variable, 'BF categories'. Instead these tangled lines appeared which doesn't make sense. I'd like to have each lines in each panel in different colors associated with a Legend outside the panel with information as below.

Any suggestions please? Attached is the summary data from a sampled data.

 

Legend:

 red: 1-3 months

 blue: 4-9 months

 green: 10-12 months

 brown: 13-24 months

et.c

 

SGPanel58.png

 

 

 

PROC IMPORT DATAFILE= "...\plotdata.txt" 
			OUT= B.plotdata
            DBMS=DLM REPLACE;
            GETNAMES=YES;
RUN;
proc sgpanel data=plotdata; 
panelby race agegroup/ novarname onepanel LAYOUT=LATTICE columns=5 ROWHEADERPOS=right; 
series y=pr_obs x=year/group=bf;
keylegend/  title="BF categories" position=bottom location=outside;
format race race. agegroup agegroup. year 4.0 bf bf.;
colaxis label='COHORT YEARS' fitpolicy=thin grid;
rowaxis label='PREVALENCE OF DISEASE' grid;
title 'PREVALENCE OF 'X' BY COHORT YEAR, AGE AND RACE'; 
run;

 


Accepted Solutions
Solution
‎01-08-2018 08:05 AM
Esteemed Advisor
Posts: 5,412

Re: proc sgpanel legend for group variable location=outside

It would look even worse with row headers on the outside. Perhaps the PANEL layout would be better for your graph.

 

ods graphics / height=1400 width=1200;
proc sgpanel data=plotdata; 
panelby race agegroup/ novarname onepanel LAYOUT=Panel columns=5; 
PG

View solution in original post


All Replies
Super User
Posts: 22,875

Re: proc sgpanel legend for group variable location=outside

What variable do you have that specifies those three groups you want. Don’t see anything relevant in the data. 

Super Contributor
Posts: 264

Re: proc sgpanel legend for group variable location=outside

Reeza, the variable 'bf' which has 6 levels. Legend with 3 levels in my post wasn't meant to be exact.
Esteemed Advisor
Posts: 5,412

Re: proc sgpanel legend for group variable location=outside

I fixed a few minor problems in this version

 

PROC IMPORT DATAFILE= "&sasforum\datasets\plotdata.txt" 
			OUT= plotdata
            DBMS=DLM REPLACE;
            GETNAMES=YES;
RUN;

proc sort data=plotdata; by race agegroup bf year; run;

ods graphics / height=1200 width=1200;
proc sgpanel data=plotdata; 
panelby race agegroup/ novarname onepanel LAYOUT=LATTICE ROWHEADERPOS=right; 
series y=pr_obs x=year / group=bf lineattrs=(pattern=solid);
keylegend/  title="BF categories" position=bottom;
*format race race. agegroup agegroup. year 4.0 bf bf.;
colaxis label='COHORT YEARS' fitpolicy=thin valuesformat=best4.0;
rowaxis label='PREVALENCE OF DISEASE';
title "PREVALENCE OF 'X' BY COHORT YEAR, AGE AND RACE"; 
run;

SGPanel3.png

 

PG
Super Contributor
Posts: 264

Re: proc sgpanel legend for group variable location=outside

Great!!! Thanks Pgstat and Reeza. Below is the code with your inputs reflected. One last thing, because chart is getting large in size, I'd like to have ROWHEADERPOS=both COLHEADERPOS=both options for easire eyeballing. Currently, row and col headers I guess are interfered by axis titles at left and bottom. Is there anyway to have row/col headers stick to the body of the chart? not split by axis titles?  Like in the image?

HEADERS BOTH.png

 



proc sort data=b.plotdata; by race agegroup bf year; run;
ods graphics / height=1200 width=4000;
proc sgpanel data=plotdata1;
panelby race agegroup/ novarname onepanel LAYOUT=LATTICE ROWHEADERPOS=both COLHEADERPOS=both;
series y=pr_obs x=year / group=bf lineattrs=(pattern=solid);
keylegend/  title="Categories" position=bottom;
*format race race. agegroup agegroup. bf bf.;
colaxis label='YEARS' fitpolicy=thin valuesformat=best4.0 values=(2002 to 2015 by 1);
rowaxis label='PREVALENCE OF DISEASE' grid;
title "TITLE";
run;

Solution
‎01-08-2018 08:05 AM
Esteemed Advisor
Posts: 5,412

Re: proc sgpanel legend for group variable location=outside

It would look even worse with row headers on the outside. Perhaps the PANEL layout would be better for your graph.

 

ods graphics / height=1400 width=1200;
proc sgpanel data=plotdata; 
panelby race agegroup/ novarname onepanel LAYOUT=Panel columns=5; 
PG
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 178 views
  • 3 likes
  • 3 in conversation