<?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: sas log doesn't show the correct value of Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741361#M231748</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello team,&lt;BR /&gt;I have this code from SAS support white paper. I can send it to you if you want.&lt;BR /&gt;The original code has used this select " ' " || diagcode || " ' ". It gave errors with a red line under ||, that is why I changed it to &amp;amp;.&lt;BR /&gt;Regards,&lt;BR /&gt;Blue Blue&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If&amp;nbsp; a paper used syntax and that syntax generates an error then you should run the syntax as originally written and if you get an error copy the text from the LOG with code and errors and all messages for the data or proc step and paste the copied text into a text box opened on the forum with the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pretty much guarantee that if you randomly attempt to use other language syntax that it will fail OR do something that you do not expect. &amp;amp; is either a logical operator for 'and' or part of a macro variable reference in general with SAS code.&lt;/P&gt;</description>
    <pubDate>Fri, 14 May 2021 08:46:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-05-14T08:46:05Z</dc:date>
    <item>
      <title>sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741241#M231683</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I run this code multiple times, the log doesn't show the result of macro correctly:&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Blue Blue&lt;/P&gt;
&lt;PRE&gt;data diag;
input diagcode$;
cards;
202
203
203
;
Run;
Proc SQL noprint;
select " ' " &amp;amp; diagcode &amp;amp; " ' ";
into : alist
separated by ' , '
from diag;
Quit;

%put &amp;amp;alist;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 May 2021 19:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741241#M231683</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-05-13T19:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741259#M231692</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I run this code multiple times, the log doesn't show the result of macro correctly:&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Blue Blue&lt;/P&gt;
&lt;PRE&gt;data diag;
input diagcode$;
cards;
202
203
203
;
Run;
Proc SQL noprint;
select " ' " &amp;amp; diagcode &amp;amp; " ' ";
into : alist
separated by ' , '
from diag;
Quit;

%put &amp;amp;alist;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, what does it show and what do you expect it to show? One of the issues is that your Proc SQL code shown has an ERROR that does not generate anything. So if "alist" is getting output with any value it was from code other than what you show.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;122  Proc SQL noprint;
123  select " ' " &amp;amp; diagcode &amp;amp; " ' ";
                                    -
                                    22
                                    76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &amp;amp;, *, **, +,
              ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT,
              FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH, LET, LIKE,
              LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

124  into : alist
            -----
            180
ERROR 180-322: Statement is not valid or it is used out of proper order.

125  separated by ' , '
126  from diag;
127  Quit;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest using one of the SAS CAT functions to build a string.&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 19:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741259#M231692</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-13T19:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741260#M231693</link>
      <description>&lt;P&gt;Quite to the contrary, the log shows the value 100% correctly.&amp;nbsp; It's the results of a program, so it is actually incapable of showing the value incorrectly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps the logic to create the macro variable is incorrect.&amp;nbsp; It certainly has an extra semicolon (at the end of the SELECT line).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you think the correct result would be?&amp;nbsp; What result did you actually get?&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 19:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741260#M231693</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-05-13T19:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741273#M231700</link>
      <description>&lt;P&gt;Use the QUOTE() function to quote a string.&amp;nbsp; It is easier and it is also critical if the value could contain quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diag;
  input diagcode $;
cards;
202
203
203
;

proc sql noprint;
select quote(trim(diagcode))
  into : alist separated by ','
  from diag
;
quit;
%put &amp;amp;=sqlobs &amp;amp;=alist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;3431  %put &amp;amp;=sqlobs &amp;amp;=alist;
SQLOBS=3 ALIST="202","203","203"
&lt;/PRE&gt;
&lt;P&gt;If you really need the single quotes (are you using pass thru SQL?) then use optional second argument to QUOTE().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;quote(trim(diagcode),"'")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you are not using pass thru SQL then you can use a space between the quoted values instead of the comma.&amp;nbsp; The IN operator in SAS is just as happy to have spaces instead of commas (or a mix of both).&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where diag in ("202" "203" "203")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And a macro variable without commas is much easier to use as an argument to a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mymacro(codelist=&amp;amp;alist)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 May 2021 20:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741273#M231700</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-13T20:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741327#M231721</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt; means &lt;STRONG&gt;and&lt;/STRONG&gt; in this context, and SAS tries to compute a Boolean.&lt;/P&gt;
&lt;P&gt;The concatenation operator is ||.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 01:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741327#M231721</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-05-14T01:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741352#M231740</link>
      <description>Hello team,&lt;BR /&gt;I have this code from SAS support white paper. I can send it to you if you want.&lt;BR /&gt;The original code has used this select " ' " || diagcode || " ' ". It gave errors with a red line under ||, that is why I changed it to &amp;amp;.&lt;BR /&gt;Regards,&lt;BR /&gt;Blue Blue</description>
      <pubDate>Fri, 14 May 2021 05:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741352#M231740</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-05-14T05:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741353#M231741</link>
      <description>How to use cat functions?&lt;BR /&gt;Regards,&lt;BR /&gt;Blue Blue</description>
      <pubDate>Fri, 14 May 2021 05:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741353#M231741</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-05-14T05:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741354#M231742</link>
      <description>&lt;P&gt;&lt;SPAN&gt;So, what does it show and what do you expect it to show? One of the issues is that your Proc SQL code shown has an ERROR that does not generate anything. So if "alist" is getting output with any value it was from code other than what you show.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The log itself shows the code. I need alist shows diagcodes separated by comma.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Respectfully,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Blue Blue&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 05:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741354#M231742</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-05-14T05:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: sas log doesn't show the correct value of Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741361#M231748</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello team,&lt;BR /&gt;I have this code from SAS support white paper. I can send it to you if you want.&lt;BR /&gt;The original code has used this select " ' " || diagcode || " ' ". It gave errors with a red line under ||, that is why I changed it to &amp;amp;.&lt;BR /&gt;Regards,&lt;BR /&gt;Blue Blue&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If&amp;nbsp; a paper used syntax and that syntax generates an error then you should run the syntax as originally written and if you get an error copy the text from the LOG with code and errors and all messages for the data or proc step and paste the copied text into a text box opened on the forum with the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pretty much guarantee that if you randomly attempt to use other language syntax that it will fail OR do something that you do not expect. &amp;amp; is either a logical operator for 'and' or part of a macro variable reference in general with SAS code.&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 08:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-log-doesn-t-show-the-correct-value-of-Macro/m-p/741361#M231748</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-14T08:46:05Z</dc:date>
    </item>
  </channel>
</rss>

