<?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: %let from string with multiple values separated by + in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462573#M117789</link>
    <description>&lt;P&gt;The macro variables are local to the macro function so they are not resolved outside the macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fix:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector=1804+1803+1712;
%let k=3;
%put &amp;amp;vector.;

%macro Macro0;
%DO i=1 %TO &amp;amp;k.;
%global mon&amp;amp;i.;                                      /*Added*/
%let mon&amp;amp;i.=%scan(&amp;amp;vector.,&amp;amp;i.,+);
%end;
%mend;
%Macro0;
%put &amp;amp;Mon1.;
%put &amp;amp;Mon2.;
%put &amp;amp;Mon3.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let us know if it helped.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 May 2018 07:13:28 GMT</pubDate>
    <dc:creator>Satish_Parida</dc:creator>
    <dc:date>2018-05-16T07:13:28Z</dc:date>
    <item>
      <title>%let from string with multiple values separated by +</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462567#M117787</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Please see this program.&lt;/P&gt;&lt;P&gt;Why &amp;nbsp;&lt;SPAN&gt;%put &amp;amp;Mon3.; &amp;nbsp;is &amp;nbsp;not recognized???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let vector=1804+1803+1712;&lt;BR /&gt;%let k=3;&lt;BR /&gt;%put &amp;amp;vector.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;%macro Macro0;&lt;BR /&gt;%DO i=1 %TO &amp;amp;k.;&lt;BR /&gt;%let mon&amp;amp;i.=%scan(&amp;amp;vector.,&amp;amp;i.,+);&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%Macro0;&lt;BR /&gt;%put &amp;amp;Mon1.;&lt;BR /&gt;%put &amp;amp;Mon2.;&lt;BR /&gt;%put &amp;amp;Mon3.;&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 06:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462567#M117787</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-05-16T06:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: %let from string with multiple values separated by +</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462571#M117788</link>
      <description>&lt;P&gt;I am sure this has already been mentioned to you before,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the code window to present code, it is the {i} above the post area.&lt;/P&gt;
&lt;P&gt;Macro is not a replacement for Base SAS, it is a limited text find/replace.&amp;nbsp; Do data processing in Base SAS!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You code fails to work for any of the macro variables, the reason being is that the macro variables created inside the macro are local to the macro, therefore do not exist outside the macro - another really good reason to not be doing data processing in macro!!&amp;nbsp; If I had to write it, I would do:&lt;/P&gt;
&lt;PRE&gt;%let vector=1804+1803+1712;

data _null_;
  do i=1 to countw("&amp;amp;vector.");
    call symput(cats('mon',put(i,best.)),scan("&amp;amp;vector.",i,"+"));
  end;
run;
%put &amp;amp;Mon1.;
%put &amp;amp;Mon2.;
%put &amp;amp;Mon3.;&lt;/PRE&gt;
&lt;P&gt;Or you&amp;nbsp; could fix your code:&lt;/P&gt;
&lt;PRE&gt;%let vector=1804+1803+1712;

%let k=3;

%macro Macro0;
  %DO i=1 %TO &amp;amp;k.;
    %global mon&amp;amp;i.;
    %let mon&amp;amp;i.=%scan(&amp;amp;vector.,&amp;amp;i.,+);
  %end;
%mend;
%Macro0;
%put &amp;amp;Mon1.;
%put &amp;amp;Mon2.;
%put &amp;amp;Mon3.;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 07:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462571#M117788</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-16T07:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: %let from string with multiple values separated by +</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462573#M117789</link>
      <description>&lt;P&gt;The macro variables are local to the macro function so they are not resolved outside the macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fix:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector=1804+1803+1712;
%let k=3;
%put &amp;amp;vector.;

%macro Macro0;
%DO i=1 %TO &amp;amp;k.;
%global mon&amp;amp;i.;                                      /*Added*/
%let mon&amp;amp;i.=%scan(&amp;amp;vector.,&amp;amp;i.,+);
%end;
%mend;
%Macro0;
%put &amp;amp;Mon1.;
%put &amp;amp;Mon2.;
%put &amp;amp;Mon3.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let us know if it helped.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 07:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462573#M117789</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-05-16T07:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: %let from string with multiple values separated by +</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462575#M117790</link>
      <description>&lt;P&gt;Apart from the good and valid suggestions you aready got, I see another issue:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector=1804+1803+1712;
%let k=3;

%macro macro0;
%do i=1 %to &amp;amp;k.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;amp;k is a redundant value; you will always be forced to change it along with &amp;amp;vector. Miss that change once, and you'll end up with a bug that can be very hard to find. Make your code as much data-driven as you can:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector=1804+1803+1712;

%macro macro0;
%do i=1 %to %sysfunc(countw(&amp;amp;vector,+));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is a ballot idea by me that asks for the creation of a %countw() macro function to complement the existing %scan(). This would remove the need for %sysfunc here.&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 07:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462575#M117790</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-16T07:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: %let from string with multiple values separated by +</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462578#M117792</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;Try this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let vector=1804+1803+1712;&lt;/P&gt;&lt;P&gt;%let k=3;&lt;BR /&gt;%put &amp;amp;vector.;&lt;/P&gt;&lt;P&gt;options symbolgen mprint mlogic;&lt;BR /&gt;%macro Macro0;&lt;BR /&gt;%DO i=1 %TO &amp;amp;k;&lt;BR /&gt;%let mon&amp;amp;i=%scan(&amp;amp;vector,&amp;amp;i);&lt;BR /&gt;%end;&lt;BR /&gt;%put &amp;amp;mon1;&lt;BR /&gt;%put &amp;amp;mon2;&lt;BR /&gt;%put &amp;amp;mon3;&lt;BR /&gt;%mend;&lt;BR /&gt;%macro0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Srianth.&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 07:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462578#M117792</guid>
      <dc:creator>srinath3111</dc:creator>
      <dc:date>2018-05-16T07:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: %let from string with multiple values separated by +</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462728#M117842</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;Can you please go through and mark the questions that you've posted with the correct answers. Volunteers have taken the time to provide answers, acknowledging the responses is polite and ensures that people will still be willing to help you in the future.&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 14:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-from-string-with-multiple-values-separated-by/m-p/462728#M117842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-16T14:53:52Z</dc:date>
    </item>
  </channel>
</rss>

