<?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 %scan only reads first character of macro array variable value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418151#M280407</link>
    <description>&lt;P&gt;The following code creates a macro array variable and then runs a macro that scans the array and outputs each variable in the log.&amp;nbsp;&amp;nbsp; However, the output is only the first numeric value.&amp;nbsp;&amp;nbsp; How can I get %scan to read each variable completely, including the characters and special characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; sample=-1.0% -2.0% 0.0 1.0xAF 2.0xAF;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;test&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;sample,&amp;amp;i);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;test&lt;/I&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2017 14:04:47 GMT</pubDate>
    <dc:creator>Batman</dc:creator>
    <dc:date>2017-12-04T14:04:47Z</dc:date>
    <item>
      <title>%scan only reads first character of macro array variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418151#M280407</link>
      <description>&lt;P&gt;The following code creates a macro array variable and then runs a macro that scans the array and outputs each variable in the log.&amp;nbsp;&amp;nbsp; However, the output is only the first numeric value.&amp;nbsp;&amp;nbsp; How can I get %scan to read each variable completely, including the characters and special characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; sample=-1.0% -2.0% 0.0 1.0xAF 2.0xAF;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;test&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;sample,&amp;amp;i);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;test&lt;/I&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 14:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418151#M280407</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2017-12-04T14:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: %scan only reads first character of macro array variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418154#M280408</link>
      <description>&lt;P&gt;Some starter for you:&lt;/P&gt;
&lt;P&gt;1) Macro has no concept of array - this is datastep component&lt;/P&gt;
&lt;P&gt;2) Read the documentation on %scan(), in particular the delimiter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Ask yourself, if Base SAS - the programming language - provides the data constructs, processing power, and simple coding - why would you want to start trying to push this through a text replacement facility?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To correct your code (note I add dots after macro variables and semicolon to finish a line):&lt;/P&gt;
&lt;PRE&gt;%let sample=-1.0% -2.0% 0.0 1.0xAF 2.0xAF;
%macro test;
  %do i=1 %to 6;
    %put %scan(&amp;amp;sample.,&amp;amp;i., );
  %end;
%mend;
 
%test;&lt;/PRE&gt;
&lt;P&gt;The main change is I put a space as the third parameter to the %scan call.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 14:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418154#M280408</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-04T14:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: %scan only reads first character of macro array variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418158#M280409</link>
      <description>&lt;P&gt;Your initial code just output the entire macro value not the individual array&amp;nbsp;values&amp;nbsp;(I accept SAS doesn't have really have macro arrays but I've seen write ups referring to them as such).&amp;nbsp;&amp;nbsp; However, it worked once I put ' ' as the delimiter.&amp;nbsp;&amp;nbsp; In reference to your last point, this was an excerpt of a larger program where the array values can vary depending on data steps previous to this one.&amp;nbsp;&amp;nbsp; In any case, thanks for your response.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 14:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418158#M280409</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2017-12-04T14:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: %scan only reads first character of macro array variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418159#M280410</link>
      <description>&lt;P&gt;I was surprised and happy to see that the &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;code worked for me, as is.&amp;nbsp; Perhaps this is a&amp;nbsp;recent addition, and only works in 9.4?&amp;nbsp; Formerly, you would need to add the delimiter of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%str( )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that using ' ' as the delimiter will use blanks as delimiters, but will also use single quotes as delimiters.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 14:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-only-reads-first-character-of-macro-array-variable-value/m-p/418159#M280410</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-04T14:30:49Z</dc:date>
    </item>
  </channel>
</rss>

