<?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: Is there a way to convert a macro variable with multiple values (in a long string) into multiple in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837439#M331102</link>
    <description>&lt;P&gt;There is usually no need to create so many macro variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use one macro variable to hold the current word from the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let carbrand = bmw ford lincoln honda toyota nissan;
%do index=1 %to %sysfunc(countw(&amp;amp;carbrand,%str( )));
  %let car=%scan(&amp;amp;carbrand,&amp;amp;index,%str( ));
  %* code that uses &amp;amp;CAR for something ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2022 18:01:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-10-07T18:01:38Z</dc:date>
    <item>
      <title>Is there a way to convert a macro variable with multiple values (in a long string) into multiple mac</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837331#M331055</link>
      <description>&lt;P&gt;Is there a way to convert a macro variable with multiple values (in a long string) into multiple macro variables?&lt;/P&gt;&lt;P&gt;I have a macro variable as below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let carbrand = bmw ford lincoln honda toyota nissan;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to convert it to multiple macro variables as below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Reading &amp;amp;carbrand. and create new macro variables:
car1=bmw
car2=ford
car3=lincoln
....
....
car6=nissan

all carN are macro variables&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So, I can only think of assigning the long string of &amp;amp;carbrand. into a datastep, and by using scan function, assign it into multiple rows in a datastep. Then, using proc sql select into to assign it back to Macro Variables (carN). However, I am sure there is a simpler and faster function to perform that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seeking for further advice.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 07:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837331#M331055</guid>
      <dc:creator>StickyRoll</dc:creator>
      <dc:date>2022-10-07T07:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to convert a macro variable with multiple values (in a long string) into multiple</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837345#M331061</link>
      <description>Macro language supports that type of a loop.  For example, inside a macro definition you could code:&lt;BR /&gt;&lt;BR /&gt;%do n=1 %to 6;&lt;BR /&gt;   %let car&amp;amp;n = %scan(&amp;amp;carbrand, &amp;amp;n);&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;There could be small issues along the way.  For example you may need to add inside the loop:&lt;BR /&gt;&lt;BR /&gt;%global car&amp;amp;n;</description>
      <pubDate>Fri, 07 Oct 2022 09:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837345#M331061</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-10-07T09:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to convert a macro variable with multiple values (in a long string) into multiple</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837432#M331099</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;%macro dummy;
%let carbrand = bmw ford lincoln honda toyota nissan;

%do i=1 %to %sysfunc(countw(&amp;amp;carbrand));
   %global car&amp;amp;i;
   %let car&amp;amp;i = %scan(&amp;amp;carbrand.,&amp;amp;i);
%end;

%mend;

%dummy;&lt;/PRE&gt;
&lt;P&gt;If you have "words" that include a space you need to use a delimiter in your list and tell the COUNTW and %SCAN functions to use that delimiter.&lt;/P&gt;
&lt;P&gt;I have a %global so the variables persist outside of this specific macro. If you need them outside of the macro I would suggest providing the result of count as well as a macro variable so it is available if needed.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 15:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837432#M331099</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-07T15:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to convert a macro variable with multiple values (in a long string) into multiple</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837439#M331102</link>
      <description>&lt;P&gt;There is usually no need to create so many macro variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use one macro variable to hold the current word from the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let carbrand = bmw ford lincoln honda toyota nissan;
%do index=1 %to %sysfunc(countw(&amp;amp;carbrand,%str( )));
  %let car=%scan(&amp;amp;carbrand,&amp;amp;index,%str( ));
  %* code that uses &amp;amp;CAR for something ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 18:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-convert-a-macro-variable-with-multiple-values/m-p/837439#M331102</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-07T18:01:38Z</dc:date>
    </item>
  </channel>
</rss>

