<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to show Keylegend for SGPanel with multiple rows arranged by cohort and subjid? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863309#M341033</link>
    <description>&lt;P&gt;I think this comes close to what you are asking for.&lt;/P&gt;
&lt;P&gt;Separate legends sort of imply separate plots. So the data is changed to plot a different y variable in each plot panel. Then use the EXCLUDE= option for each separate keylegend to only show the subjid for the cohort.&lt;/P&gt;
&lt;PRE&gt;data test;
	cohort = 1;subjid = '011';aval = 10; ady = 1; output;
	cohort = 1;subjid = '012';aval = 15; ady = 1; output;
	cohort = 2;subjid = '021';aval2 = 20; ady = 2; output;
	cohort = 3;subjid = '031';aval3 = 30; ady = 3; output;
run;

proc sort data=test; by cohort subjid; run;

proc sgpanel data=test;
	panelby cohort / columns=1 spacing=5 novarname HEADERATTRS=(Family=Arial Size=11 Weight=Bold);
	series x=ady y=aval / markers group=subjid markerattrs=(symbol=circle) name='p1' ;
	series x=ady y=aval2 / markers group=subjid markerattrs=(symbol=circle) name='p2' ;
	series x=ady y=aval3 / markers group=subjid markerattrs=(symbol=circle) name='p3' ;
	keylegend 'p1' /title='Corhort 1' exclude=('021' '031') titleattrs=(size=8 family='Arial' weight=bold);
	keylegend 'p2' /title='Corhort 2' exclude=('011' '012' '031') titleattrs=(size=8 family='Arial' weight=bold);
	keylegend 'p3' /title='Corhort 3' exclude=('011' '012' '021') titleattrs=(size=8 family='Arial' weight=bold);

	colaxis offsetmin=0.05 offsetmax=0.01 values=(-1 1 2 3 ) valueattrs=(weight=bold size=8 family='Arial')
	      valuesdisplay=('Baseline' 'Day 1' 'Day 2' 'Day 3') 
	      label='Study Day' labelattrs=(weight=bold size=11 family='Arial') fitpolicy=rotate;
	rowaxis label="Param" labelattrs=(weight=bold family='Arial' size=11);

	refline 1 / axis=x lineattrs=(thickness=1 color=lightgray pattern=solid);
run;&lt;/PRE&gt;
&lt;P&gt;There might be a cleaner way with Annotate data.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Mar 2023 21:39:23 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-03-09T21:39:23Z</dc:date>
    <item>
      <title>How to show Keylegend for SGPanel with multiple rows arranged by cohort and subjid?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863290#M341023</link>
      <description>&lt;P&gt;I have a dummy dataset with 3 cohorts: 1, 2 and 3. In each cohort there are subjects (Cohort 1: 011, 012. Cohort2: 021. Cohort 3: 031). I want the keylegend to show 3 rows with row 1 "Cohort 1: 011 012", row 2 "Cohort 2: 021", and row 3 "Cohort 3: 031". I don't know how. Below is the data and plot.&lt;/P&gt;
&lt;PRE&gt;data test;
	cohort = 1;subjid = '011';aval = 10; ady = 1; output;
	cohort = 1;subjid = '012';aval = 15; ady = 1; output;
	cohort = 2;subjid = '021';aval = 20; ady = 2; output;
	cohort = 3;subjid = '031';aval = 30; ady = 3; output;
run;

proc sort data=test; by cohort subjid; run;

proc sgpanel data=test;
	panelby cohort / columns=1 spacing=5 novarname HEADERATTRS=(Family=Arial Size=11 Weight=Bold);
	series x=ady y=aval / markers group=subjid markerattrs=(symbol=circle) ;
	keylegend /title='Subject' titleattrs=(size=8 family='Arial' weight=bold);

	colaxis offsetmin=0.05 offsetmax=0.01 values=(-1 1 2 3 ) valueattrs=(weight=bold size=8 family='Arial')
	      valuesdisplay=('Baseline' 'Day 1' 'Day 2' 'Day 3') 
	      label='Study Day' labelattrs=(weight=bold size=11 family='Arial') fitpolicy=rotate;
	rowaxis label="Param" labelattrs=(weight=bold family='Arial' size=11);

	refline 1 / axis=x lineattrs=(thickness=1 color=lightgray pattern=solid);
run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2023 20:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863290#M341023</guid>
      <dc:creator>jsbyxws</dc:creator>
      <dc:date>2023-03-09T20:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to show Keylegend for SGPanel with multiple rows arranged by cohort and subjid?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863309#M341033</link>
      <description>&lt;P&gt;I think this comes close to what you are asking for.&lt;/P&gt;
&lt;P&gt;Separate legends sort of imply separate plots. So the data is changed to plot a different y variable in each plot panel. Then use the EXCLUDE= option for each separate keylegend to only show the subjid for the cohort.&lt;/P&gt;
&lt;PRE&gt;data test;
	cohort = 1;subjid = '011';aval = 10; ady = 1; output;
	cohort = 1;subjid = '012';aval = 15; ady = 1; output;
	cohort = 2;subjid = '021';aval2 = 20; ady = 2; output;
	cohort = 3;subjid = '031';aval3 = 30; ady = 3; output;
run;

proc sort data=test; by cohort subjid; run;

proc sgpanel data=test;
	panelby cohort / columns=1 spacing=5 novarname HEADERATTRS=(Family=Arial Size=11 Weight=Bold);
	series x=ady y=aval / markers group=subjid markerattrs=(symbol=circle) name='p1' ;
	series x=ady y=aval2 / markers group=subjid markerattrs=(symbol=circle) name='p2' ;
	series x=ady y=aval3 / markers group=subjid markerattrs=(symbol=circle) name='p3' ;
	keylegend 'p1' /title='Corhort 1' exclude=('021' '031') titleattrs=(size=8 family='Arial' weight=bold);
	keylegend 'p2' /title='Corhort 2' exclude=('011' '012' '031') titleattrs=(size=8 family='Arial' weight=bold);
	keylegend 'p3' /title='Corhort 3' exclude=('011' '012' '021') titleattrs=(size=8 family='Arial' weight=bold);

	colaxis offsetmin=0.05 offsetmax=0.01 values=(-1 1 2 3 ) valueattrs=(weight=bold size=8 family='Arial')
	      valuesdisplay=('Baseline' 'Day 1' 'Day 2' 'Day 3') 
	      label='Study Day' labelattrs=(weight=bold size=11 family='Arial') fitpolicy=rotate;
	rowaxis label="Param" labelattrs=(weight=bold family='Arial' size=11);

	refline 1 / axis=x lineattrs=(thickness=1 color=lightgray pattern=solid);
run;&lt;/PRE&gt;
&lt;P&gt;There might be a cleaner way with Annotate data.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 21:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863309#M341033</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-09T21:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to show Keylegend for SGPanel with multiple rows arranged by cohort and subjid?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863419#M341069</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	cohort = 1;subjid = '011';aval = 10; ady = 1; output;
	cohort = 1;subjid = '012';aval = 15; ady = 1; output;
	cohort = 2;subjid = '021';aval = 20; ady = 2; output;
	cohort = 3;subjid = '031';aval = 30; ady = 3; output;
run;

proc sort data=test; by cohort subjid; run;

proc sgpanel data=test;
	panelby cohort / columns=1 spacing=5 novarname HEADERATTRS=(Family=Arial Size=11 Weight=Bold);
	series x=ady y=aval / markers group=subjid markerattrs=(symbol=circle) ;

legenditem name='a' type=MARKERLINE / label='011' MARKERATTRS=graphdata1 LINEATTRS=graphdata1;
legenditem name='b' type=MARKERLINE / label='012' MARKERATTRS=graphdata2 LINEATTRS=graphdata2;
legenditem name='c' type=MARKERLINE / label='021' MARKERATTRS=graphdata3 LINEATTRS=graphdata3;
legenditem name='d' type=MARKERLINE / label='031' MARKERATTRS=graphdata4 LINEATTRS=graphdata4;



keylegend 'a' 'b' /title='Corhort 1' titleattrs=(size=8 family='Arial' weight=bold) noborder;
keylegend 'c' /title='Corhort 2' titleattrs=(size=8 family='Arial' weight=bold) noborder;
keylegend 'd' /title='Corhort 3' titleattrs=(size=8 family='Arial' weight=bold) noborder;

	colaxis offsetmin=0.05 offsetmax=0.01 values=(-1 1 2 3 ) valueattrs=(weight=bold size=8 family='Arial')
	      valuesdisplay=('Baseline' 'Day 1' 'Day 2' 'Day 3') 
	      label='Study Day' labelattrs=(weight=bold size=11 family='Arial') fitpolicy=rotate;
	rowaxis label="Param" labelattrs=(weight=bold family='Arial' size=11);

	refline 1 / axis=x lineattrs=(thickness=1 color=lightgray pattern=solid);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1678453427153.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81314i82EC581B0FD034F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1678453427153.png" alt="Ksharp_0-1678453427153.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 13:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863419#M341069</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-03-10T13:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to show Keylegend for SGPanel with multiple rows arranged by cohort and subjid?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863465#M341081</link>
      <description>&lt;P&gt;Thanks a lot, KSharp!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, it solves this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in reality, the study has about 50 subjects with 15 cohort. How to make legend item list easier to code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another information: if each cohort is 3 subjects, crossover = 3 will make it multiple rows in 3 columns. But how to add cohort label "Cohort 1", "Cohort 2" etc?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863465#M341081</guid>
      <dc:creator>jsbyxws</dc:creator>
      <dc:date>2023-03-10T15:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to show Keylegend for SGPanel with multiple rows arranged by cohort and subjid?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863466#M341082</link>
      <description>&lt;P&gt;Hi Ballardw,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot for help! It works!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The actual data has about many cohorts. Each cohort has 3 subjects. It would be tedious to exclude so many subjects in reality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863466#M341082</guid>
      <dc:creator>jsbyxws</dc:creator>
      <dc:date>2023-03-10T15:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to show Keylegend for SGPanel with multiple rows arranged by cohort and subjid?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863469#M341083</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/229101"&gt;@jsbyxws&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks a lot, KSharp!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, it solves this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in reality, the study has about 50 subjects with 15 cohort. How to make legend item list easier to code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another information: if each cohort is 3 subjects, crossover = 3 will make it multiple rows in 3 columns. But how to add cohort label "Cohort 1", "Cohort 2" etc?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That would likely be ugly in SGPANEL.&lt;/P&gt;
&lt;P&gt;Did you try SGPLOT:&lt;/P&gt;
&lt;P&gt;Consider that with a BY statement then each legend is built separately and by default each plot will have the By information:&lt;/P&gt;
&lt;PRE&gt;data test;
	cohort = 1;subjid = '011';aval = 10; ady = 1; output;
	cohort = 1;subjid = '012';aval = 15; ady = 1; output;
	cohort = 2;subjid = '021';aval = 20; ady = 2; output;
	cohort = 3;subjid = '031';aval = 30; ady = 3; output;
run;

proc sort data=test; by cohort subjid; run;

proc sgplot data=test;
   by cohort;
/*	panelby cohort / columns=1 spacing=5 novarname HEADERATTRS=(Family=Arial Size=11 Weight=Bold);*/
	series x=ady y=aval / markers group=subjid markerattrs=(symbol=circle) ;
	keylegend /title='Subject' titleattrs=(size=8 family='Arial' weight=bold);

	xaxis offsetmin=0.05 offsetmax=0.01 values=(-1 1 2 3 ) valueattrs=(weight=bold size=8 family='Arial')
	      valuesdisplay=('Baseline' 'Day 1' 'Day 2' 'Day 3') 
	      label='Study Day' labelattrs=(weight=bold size=11 family='Arial') fitpolicy=rotate;
	yaxis label="Param" labelattrs=(weight=bold family='Arial' size=11);

	refline 1 / axis=x lineattrs=(thickness=1 color=lightgray pattern=solid);
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863469#M341083</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-10T15:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to show Keylegend for SGPanel with multiple rows arranged by cohort and subjid?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863494#M341087</link>
      <description>&lt;P&gt;Thanks! I will give it a try.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 16:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-show-Keylegend-for-SGPanel-with-multiple-rows-arranged-by/m-p/863494#M341087</guid>
      <dc:creator>jsbyxws</dc:creator>
      <dc:date>2023-03-10T16:42:55Z</dc:date>
    </item>
  </channel>
</rss>

