<?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: Change variable names in legend in Proc SGPanel in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576948#M23103</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241893"&gt;@joebacon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;First, thank you for taking the time to look over this and respond&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;. I am very appreciative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The renaming was solely for the purpose of changing the legend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used a solution like you stated first with the OPTION VALIDVARNAME=ANY;. It worked quite well, but i suspected that it wasn't the best way to handle the situation. I tried to format each of the variables but felt silly after doing it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't even think to label the variables. Very smart. Would the labels appear in the legend of the sgpanel graph? I am going to try now, but will close the question as you handled it!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Legends will attempt to use the label of a variable by default. If no label is associated with the variable the name is used. Example:&lt;/P&gt;
&lt;PRE&gt;proc sgpanel data=sashelp.class;
    panelby sex ;
    scatter x=age y=height;
    scatter x=age y=weight;
    label height="Height at age"
          weight="Weight at enrollment"
   ;
  
run;&lt;/PRE&gt;
&lt;P&gt;The SAS supplied data set sashelp.class does not have labels associated with the variables so without this label statement the variable name is use.&lt;/P&gt;
&lt;P&gt;Also you can override a variable label for&amp;nbsp;almost any&amp;nbsp;specific procedure that produces displayed output. So if you get a variable that had a very long label, as does occur, such as the entire text of question you could replace with something shorter in you graphs by providing a different label in the procedure code. That would not change the permanent label associated with the variable.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2019 15:45:23 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-07-26T15:45:23Z</dc:date>
    <item>
      <title>Change variable names in legend in Proc SGPanel</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576702#M23089</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having a little issue with changing the variable names in the legend of PRC SGPANEL. Ballard had a great response to a similar question explaining the power of proc format. However, my data is a little different because I apply three different variables on the Y axis from three different lines. My current code looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Quarter(data,category,out,label,title);
	proc sql;
		  create table &amp;amp;category._&amp;amp;out. as select 
		  mean(I_PreResYr1stT_&amp;amp;category)  as Pre_Q1,
		  mean(I_PreResYr2ndT_&amp;amp;category)  as Pre_Q2,
		  mean(I_PreResYr3rdT_&amp;amp;category)  as Pre_Q3,
		  mean(I_PostResYr1stT_&amp;amp;category) as Pos_Q1,
		  mean(I_PostResYr2ndT_&amp;amp;category) as Pos_Q2,
		  mean(I_PostResYr3rdT_&amp;amp;category) as Pos_Q3
		  from &amp;amp;data
		  where TRICHOT_1YR ne . and Full_Alc_Exp = 1
		  group by TRICHOT_1YR;
		  quit;

	proc transpose data=&amp;amp;category._&amp;amp;out. out=&amp;amp;category._&amp;amp;out.;run;

	data &amp;amp;category._&amp;amp;out. ; set &amp;amp;category._&amp;amp;out. ; 
	rename COL1	=RA COL2	=UR COL3	=RNA; run;
Proc Format;
value $DS
"RA"="Resolved Abstinent"
"RNA" = "Resolved Non-abstinent"
"UR" = "Unresolved";
run;
	data &amp;amp;category._&amp;amp;out.;
		set &amp;amp;category._&amp;amp;out.;
		Quadrimester = substr(_NAME_,5,2);
		if substr(_NAME_,1,3)="Pos" then Year="Post-Resolution Year";
		if substr(_NAME_,1,3)="Pre" then Year="Pre-Resolution Year";
		drop _NAME_;
		run;

ods graphics / reset=all border=off width=650px height=400px;
title height=0.2in "&amp;amp;title"; 
	proc sgpanel data=&amp;amp;category._&amp;amp;out. noautolegend;
	
		panelby Year/sort=(descformat) headerattrs=(family=arial size= 16pt weight=bold) novarname;
		series x=Quadrimester y=RA/
		markers markerattrs=(symbol=circlefilled size=3pct color=green) lineattrs=(color=green thickness=4 pattern=longdash);
		series x=Quadrimester y=UR/
		markers markerattrs=(symbol=circlefilled size=3pct color=blue) lineattrs=(color=blue thickness=4 pattern=ShortDashDot);
		series x=Quadrimester y=RNA/
		markers markerattrs=(symbol=circlefilled size=3pct color=red) lineattrs=(color=red thickness=3 pattern=solid);

		rowaxis label="&amp;amp;label" labelattrs=(family=arial size=16pt weight=bold ) valueattrs=(family=arial size=16pt weight=bold);
		colaxis label=' ' labelattrs=(size=16pt ) valueattrs=(family=arial weight=bold size=16pt );	
		run;
%mend;


ods rtf  file="U:\Documents\ARC Expenditure and Integrity\SinglePaneTrendPlot_071519.rtf"  gtitle bodytitle;

%Quarter(sub.newcatinflation2,TLFPL  ,Q, Inflation-Adjusted Dollars, Quadrimester Trend for Financial and Legal Affairs );
%Quarter(sub.newcatinflation2,DurInsHouse  ,Q, Inflation-Adjusted Dollars, Quadrimester Trend for Housing/Durable Goods/Insurance );

ods rtf close;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I also have tried to address this when I rename columns by renaming the columns "Resolved Abstinent", "unresolved", and "Resolved Non-abstinent" like so:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	proc transpose data=&amp;amp;category._&amp;amp;out. out=&amp;amp;category._&amp;amp;out.;run;

	data &amp;amp;category._&amp;amp;out. ; set &amp;amp;category._&amp;amp;out. ; 
	rename COL1	="Resolved Abstinent" COL2	=UR COL3	=RNA; run;

	data &amp;amp;category._&amp;amp;out.;
		set &amp;amp;category._&amp;amp;out.;
		Quadrimester = substr(_NAME_,5,2);
		if substr(_NAME_,1,3)="Pos" then Year="Post-Resolution";
		if substr(_NAME_,1,3)="Pre" then Year="Pre-Resolution";
		drop _NAME_;
		run;

ods graphics / reset=all border=off width=650px height=400px;
title height=0.2in "&amp;amp;title"; 
footnote justify=center "&amp;amp;footnote";
	proc sgpanel data=&amp;amp;category._&amp;amp;out. noautolegend;
		panelby Year/sort=(descformat) headerattrs=(family=arial size= 16pt weight=bold) ;
		series x=Quadrimester y="Resolved Abstinent"/
		markers markerattrs=(symbol=circlefilled size=3pct color=blue) lineattrs=(color=blue thickness=4 pattern=longdash);
		series x=Quadrimester y=UR/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I get errors saying:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: There were 3 observations read from the data set WORK.CONSUME_Q.
NOTE: The data set WORK.CONSUME_Q has 6 observations and 4 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 22-322: Expecting a name.  
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: The SAS System stopped processing this step because of errors.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an easy way which I can rename the legend variables? P.S. I do recognize that right now I have "noautolegend" right now. I had it on for a different graph. The results without this are the same.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 17:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576702#M23089</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2019-07-25T17:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable names in legend in Proc SGPanel</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576734#M23092</link>
      <description>&lt;P&gt;I found another post that showed me a work around. Though I do not think this is the best way, it seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed the options before I renamed the columns to options validvarname=any. Then, I was able to use spaces in my variables. From there, I added options validmemname=extend and used those same variables. Make sure to not forget the 'n' after these variables with a space. My new code reads:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	proc transpose data=&amp;amp;category._&amp;amp;out. out=&amp;amp;category._&amp;amp;out.;run;
options validvarname=any;
	data &amp;amp;category._&amp;amp;out. ; set &amp;amp;category._&amp;amp;out. ; 
	rename COL1	='Resolved Abstinent'n COL2	='Unresolved'n COL3	='Resolved Non-abstinent'n; run;
options validmemname=extend;
	data &amp;amp;category._&amp;amp;out.;
		set &amp;amp;category._&amp;amp;out.;
		Quadrimester = substr(_NAME_,5,2);
		if substr(_NAME_,1,3)="Pos" then Year="Post Resolution";
		if substr(_NAME_,1,3)="Pre" then Year="Pre Resolution";
		drop _NAME_;
		run;
options validmemname=extend;
ods graphics / reset=all border=off width=700px height=500px;
title height=0.2in "&amp;amp;title"; 
	proc sgpanel data=&amp;amp;category._&amp;amp;out.;
		panelby Year/sort=(descformat) headerattrs=(weight=bold) ;
		series x=Quadrimester y='Resolved Abstinent'n/
		markers markerattrs=(symbol=circlefilled size=3pct color=green) lineattrs=(color=green thickness=4 pattern=longdash);
		series x=Quadrimester y='Unresolved'n/
		markers markerattrs=(symbol=circlefilled size=3pct color=blue) lineattrs=(color=blue thickness=4 pattern=ShortDashDot);
		series x=Quadrimester y='Resolved Non-abstinent'n/
		markers markerattrs=(symbol=circlefilled size=3pct color=red) lineattrs=(color=red thickness=4 pattern=solid);

		rowaxis label="&amp;amp;label" labelattrs=(size=12pt weight=bold) valueattrs=(size=12pt weight=bold);
		colaxis label=' ' labelattrs=(size=12pt weight=bold) valueattrs=(size=12pt weight=bold);
		keylegend /valueattrs=(family= arial weight=bold Size=12 );	
		run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks to those who looked at this!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 20:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576734#M23092</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2019-07-25T20:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable names in legend in Proc SGPanel</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576735#M23093</link>
      <description>&lt;P&gt;First why is renaming the variable important?&lt;/P&gt;
&lt;P&gt;Second basically SAS does not allow by default any spaces in a variable name. If you set the OPTION VALIDVARNAME=ANY; you can use non-standard names but the reference then becomes "New name"n&amp;nbsp;&amp;nbsp; &amp;lt;= that n &lt;STRONG&gt;must&lt;/STRONG&gt; immediately follow the quote, no space. You are still limited to 32 characters for the name though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically if want test such as &lt;SPAN class="token string"&gt;"Resolved Abstinent" to appear in output instead of COL1 the approach is to assign a label to the variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token string"&gt;Consider the output of the two following proc prints:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc print data=sashelp.class (obs=5) noobs label;
run;

proc print data=sashelp.class (obs=5) noobs label;
   label age='Age of enrollment';
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="token string"&gt;Notice that the column header changes for the Age variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token string"&gt;So try instead of renaming that you use something like&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sgpanel data=&amp;amp;category._&amp;amp;out. noautolegend;
   panelby Year/sort=(descformat) headerattrs=(family=arial size= 16pt weight=bold) ;
   label col1="Resolved Abstinent";
   series x=Quadrimester y=Col1/
      markers markerattrs=(symbol=circlefilled size=3pct color=blue) lineattrs=(color=blue thickness=4 pattern=longdash);&lt;BR /&gt;/* and similar Label for each y variable used*/
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="token string"&gt;A serious advantage of the LABEL is that you can display much longer text than 32 characters&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 20:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576735#M23093</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-25T20:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable names in legend in Proc SGPanel</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576894#M23101</link>
      <description>&lt;P&gt;First, thank you for taking the time to look over this and respond&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;. I am very appreciative.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The renaming was solely for the purpose of changing the legend.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used a solution like you stated first with the OPTION VALIDVARNAME=ANY;. It worked quite well, but i suspected that it wasn't the best way to handle the situation. I tried to format each of the variables but felt silly after doing it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't even think to label the variables. Very smart. Would the labels appear in the legend of the sgpanel graph? I am going to try now, but will close the question as you handled it!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 13:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576894#M23101</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2019-07-26T13:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable names in legend in Proc SGPanel</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576948#M23103</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241893"&gt;@joebacon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;First, thank you for taking the time to look over this and respond&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;. I am very appreciative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The renaming was solely for the purpose of changing the legend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used a solution like you stated first with the OPTION VALIDVARNAME=ANY;. It worked quite well, but i suspected that it wasn't the best way to handle the situation. I tried to format each of the variables but felt silly after doing it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't even think to label the variables. Very smart. Would the labels appear in the legend of the sgpanel graph? I am going to try now, but will close the question as you handled it!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Legends will attempt to use the label of a variable by default. If no label is associated with the variable the name is used. Example:&lt;/P&gt;
&lt;PRE&gt;proc sgpanel data=sashelp.class;
    panelby sex ;
    scatter x=age y=height;
    scatter x=age y=weight;
    label height="Height at age"
          weight="Weight at enrollment"
   ;
  
run;&lt;/PRE&gt;
&lt;P&gt;The SAS supplied data set sashelp.class does not have labels associated with the variables so without this label statement the variable name is use.&lt;/P&gt;
&lt;P&gt;Also you can override a variable label for&amp;nbsp;almost any&amp;nbsp;specific procedure that produces displayed output. So if you get a variable that had a very long label, as does occur, such as the entire text of question you could replace with something shorter in you graphs by providing a different label in the procedure code. That would not change the permanent label associated with the variable.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 15:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576948#M23103</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-26T15:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable names in legend in Proc SGPanel</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576951#M23104</link>
      <description>That is quite a nuanced point that would prove exceptionally useful for me as I work with survey data quite a bit. Thank you for always going above and beyond to help us learn!</description>
      <pubDate>Fri, 26 Jul 2019 15:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Change-variable-names-in-legend-in-Proc-SGPanel/m-p/576951#M23104</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2019-07-26T15:48:26Z</dc:date>
    </item>
  </channel>
</rss>

