<?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: SGPLOT change y axis label based on values of By variable. in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744340#M21584</link>
    <description>&lt;P&gt;Tjek the YAXIS statemant with the label option&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0n6uml63c6h8dn16phbd1arm9g9.htm#n1ujjft95cl9xzn0zh4jb5yc29xcc" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0n6uml63c6h8dn16phbd1arm9g9.htm#n1ujjft95cl9xzn0zh4jb5yc29xcc&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 28 May 2021 07:22:42 GMT</pubDate>
    <dc:creator>rudfaden</dc:creator>
    <dc:date>2021-05-28T07:22:42Z</dc:date>
    <item>
      <title>SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744337#M21583</link>
      <description>&lt;P&gt;Hi, I would like to use SGPLOT to create multi graphs using By-variable statement&lt;/P&gt;&lt;P&gt;- My code is like that:&lt;/P&gt;&lt;P&gt;Proc sgplot data=database;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; by&amp;nbsp;Symptom;&lt;/P&gt;&lt;P&gt;scatter x=VisitNum y=Mean / groupdisplay=cluster&amp;nbsp;group= Treatment;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;- This is some of the graphs created:&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59827i5684C058F4407C14/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="123.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59830iAE53F98CEDB15C1E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="123.png" alt="123.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;My question is how could I change the label in the y axis to the name of variable (in this case: Symp1S Symp2S instead of Mean).&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 06:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744337#M21583</guid>
      <dc:creator>James_Yu</dc:creator>
      <dc:date>2021-05-28T06:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744340#M21584</link>
      <description>&lt;P&gt;Tjek the YAXIS statemant with the label option&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0n6uml63c6h8dn16phbd1arm9g9.htm#n1ujjft95cl9xzn0zh4jb5yc29xcc" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0n6uml63c6h8dn16phbd1arm9g9.htm#n1ujjft95cl9xzn0zh4jb5yc29xcc&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 07:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744340#M21584</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2021-05-28T07:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744443#M21587</link>
      <description>&lt;P&gt;As far as I am aware there is not way to do what you're asking directly.&amp;nbsp; I would suggest instead writing a short macro loop to do what you're trying to do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
   proc sql noprint;
       select distinct symptom,label into :vlist separated by '|',:llist separated by '|' from database;
   quit;

   %do i = 1 %to %sysfunc(countw(&amp;amp;vlist,|));
        proc sgplot data=database;   
             where symptom="%Qscan(%superq(vlist),&amp;amp;i,|)";
             scatter x=VisitNum y=Mean / groupdisplay=cluster group=Treatment;
             yaxis label="%qscan(%superq(llist),&amp;amp;i,|,m)";
        run;
    %end;
%mend;
%loop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the above code to work you would need to have another variable in your dataset, which I named label above, to contain a string you want the y-axis label to be.&amp;nbsp; If you are using output statements to make your long version of your dataset you can use the VLABEL function to grab the label from each variable automatically.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you instead of a dataset where you have the variables in separate columns instead of rows, you can instead make your loop with a %let statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
   %let vlist=var1 var2 var3 var4;
   %do i = 1 %to %sysfunc(countw(&amp;amp;vlist,|));
        proc sgplot data=database;   
             scatter x=VisitNum y=%scan(&amp;amp;vlist,&amp;amp;i,|) / groupdisplay=cluster group=Treatment;
        run;
    %end;
%mend;
%loop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This method would then use the labels from the variables themselves to be the y-axis label.&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 15:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744443#M21587</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2021-05-28T15:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744460#M21589</link>
      <description>&lt;P&gt;How about using a left-justified title2, that "looks like" a yaxis label at the top of the yaxis?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options nobyline;&lt;BR /&gt;title1 "Stock prices";&lt;BR /&gt;&lt;STRONG&gt;title2 justify=left "#byval(stock)";&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sgplot data=sashelp.stocks;&lt;BR /&gt;by stock;&lt;BR /&gt;series x=date y=close;&lt;BR /&gt;yaxis display=(nolabel) /*label="#byval(stock)"*/;&lt;BR /&gt;xaxis display=(nolabel);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yaxis_byval.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59858i929F20EE34EFAA8E/image-size/large?v=v2&amp;amp;px=999" role="button" title="yaxis_byval.png" alt="yaxis_byval.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 16:36:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744460#M21589</guid>
      <dc:creator>GraphGuy</dc:creator>
      <dc:date>2021-05-28T16:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744493#M21592</link>
      <description>&lt;P&gt;If you want the axis label in the middle of the axis, you could use SAS/Graph gplot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options nobyline;&lt;BR /&gt;title1 "Stock prices";&lt;BR /&gt;symbol1 value=none interpol=join;&lt;BR /&gt;&lt;STRONG&gt;axis1&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;label=(angle=90 "&lt;STRONG&gt;#byval(stock)&lt;/STRONG&gt;");&lt;BR /&gt;axis2 label=none;&lt;BR /&gt;proc gplot data=sashelp.stocks;&lt;BR /&gt;by stock;&lt;BR /&gt;plot close*date /&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;vaxis=axis1&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;haxis=axis2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vaxis_byval.png" style="width: 800px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59866i001177D40E9E4B0C/image-size/large?v=v2&amp;amp;px=999" role="button" title="vaxis_byval.png" alt="vaxis_byval.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 18:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744493#M21592</guid>
      <dc:creator>GraphGuy</dc:creator>
      <dc:date>2021-05-28T18:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744581#M21594</link>
      <description>&lt;P&gt;Your solution is very helpful sir. It works without any trouble&lt;/P&gt;&lt;P&gt;May I ask for another favor.&lt;/P&gt;&lt;P&gt;Because I'm pretty new to SAS so&amp;nbsp;macro loop does not seem quite familiar with me. So could you please provide more explanation to these line of code ?&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
       select distinct symptom,label into :vlist separated by '|',:llist separated by '|' from database;
   quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;FONT size="3" color="#000000"&gt;As far as I understand,&lt;/FONT&gt;&lt;FONT size="3" color="#000000"&gt; t&lt;/FONT&gt;&lt;FONT size="3" color="#000000"&gt;his&lt;/FONT&gt;&lt;FONT size="3" color="#000000"&gt; line of code create 2 macro variables&amp;nbsp;&lt;CODE class=" language-sas"&gt;vlist&lt;/CODE&gt; and&amp;nbsp;&lt;CODE class=" language-sas"&gt;llist&lt;/CODE&gt;&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;FONT face="arial, helvetica, sans-serif" size="3" color="#000000"&gt;So what do "%sysfunc(countw(&amp;amp;vlist,|))",&amp;nbsp;"%Qscan(%superq(vlist),&amp;amp;i,|)" and&amp;nbsp;"%qscan(%superq(llist),&amp;amp;i,|,m)" do in these line of codes?&lt;/FONT&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i = 1 %to %sysfunc(countw(&amp;amp;vlist,|));&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where symptom="%Qscan(%superq(vlist),&amp;amp;i,|)";&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;label="%qscan(%superq(llist),&amp;amp;i,|,m)";&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;FONT face="arial, helvetica, sans-serif" size="3" color="#000000"&gt;Thanks in advance&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 03:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744581#M21594</guid>
      <dc:creator>James_Yu</dc:creator>
      <dc:date>2021-05-29T03:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744582#M21595</link>
      <description>You are correct.  The SQL code creates two macro variables that are lists of values delimited by the | (pipe) symbol.  I typically choose this symbol because I don't see it used in strings super often.&lt;BR /&gt;&lt;BR /&gt;The COUNTW function counts how many words there are given a certain delimiter and in this case I used the | symbol to count words by.  So even if you have a label or something that is multiple actual words, it will only count by | symbols.  The COUNTW function is really handy for making loops where the number of loops might change with your data.  The %SYSFUNC portion is needed to make the function work in the macro language capacity.&lt;BR /&gt;&lt;BR /&gt;The %QSCAN is like the regular SCAN function but for the macro language.  The macro language will replace itself with its result prior to running the actual code.  In this can replace the %qscan section with the string it resolves to.  The scan function will pick the nth word in a string using a specific delimiter (again using the | pipe here).  %qscan will tell it to treat the result as macro text and will ignore things like quotations in the string which can be very handy when you have labels or something with special characters or quotes.&lt;BR /&gt;&lt;BR /&gt;The %SUPERQ function resolves the macro variable and tells the result as macro text again (this is typical of any macro function with the Q in it).  This keeps it form reading possible commas or quotes again when it puts that resolved text into the %qscan function.&lt;BR /&gt;&lt;BR /&gt;I hope this helps.</description>
      <pubDate>Sat, 29 May 2021 04:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744582#M21595</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2021-05-29T04:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744586#M21596</link>
      <description>&lt;P&gt;Thanks a lot for your clear explanation.&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 05:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744586#M21596</guid>
      <dc:creator>James_Yu</dc:creator>
      <dc:date>2021-05-29T05:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744589#M21597</link>
      <description>&lt;P&gt;May I ask a bit more details about your solution sir.&lt;/P&gt;&lt;P&gt;In my situation, I would like to add one more string to the label and place it in the title of the graph&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, I just added a title statement into the code like that:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
   proc sql noprint;
       select distinct symptom,label into :vlist separated by '|',:llist separated by '|' from database;
   quit;

   %do i = 1 %to %sysfunc(countw(&amp;amp;vlist,|));
        proc sgplot data=database;   
             where symptom="%Qscan(%superq(vlist),&amp;amp;i,|)";
             scatter x=VisitNum y=Mean / groupdisplay=cluster group=Treatment;
             yaxis label="%qscan(%superq(llist),&amp;amp;i,|,m)";
            TITLE "%qscan(%superq(llist),&amp;amp;i,|,m)";
        run;
    %end;
%mend;
%loop;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And it shows the label on the title.&lt;/P&gt;&lt;P&gt;So how could I join another string to the&amp;nbsp;"%qscan(%superq(llist),&amp;amp;i,|,m)" function to achieve a title like "Symptom: ....(the label)..."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 07:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/744589#M21597</guid>
      <dc:creator>James_Yu</dc:creator>
      <dc:date>2021-05-29T07:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT change y axis label based on values of By variable.</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/745051#M21608</link>
      <description>You can put whatever you need to within the TITLE quotes.  The %qscan will replace itself with the label amongst any other text:&lt;BR /&gt;&lt;BR /&gt;TITLE "Symptom: %qscan(%superq(llist),&amp;amp;i,|,m) and any other text you want";&lt;BR /&gt;&lt;BR /&gt;Just make sure to use double quotes or the macro functions won't work.</description>
      <pubDate>Tue, 01 Jun 2021 21:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-change-y-axis-label-based-on-values-of-By-variable/m-p/745051#M21608</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2021-06-01T21:53:27Z</dc:date>
    </item>
  </channel>
</rss>

