<?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: LOOP  TROUGH A LIST of STRINGS TO CREATE DIFFERENT FILES in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/813982#M321282</link>
    <description>&lt;P&gt;The initial issue is that you need to use SEPARATED BY in the SQL SELECT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select city into :city_list from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But there are other issues as well.&lt;/P&gt;
&lt;P&gt;Why do you create flag in the data step when you do not keep it?&lt;/P&gt;
&lt;P&gt;And you do not need the macro loop. Define the macro with next_name as parameter, and use CALL EXECUTE in a DATA _NULL_ step from dataset have to call the macro for each city.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 May 2022 03:46:33 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-05-18T03:46:33Z</dc:date>
    <item>
      <title>LOOP  TROUGH A LIST of STRINGS TO CREATE DIFFERENT FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/813980#M321280</link>
      <description>&lt;P&gt;Hi all, I need help running the loop. It works only for the first city.&lt;/P&gt;&lt;P&gt;I need each city in a separate file with its length.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA have;&lt;BR /&gt;city="TORONTO";L=LENGTH(CITY); OUTPUT;&lt;BR /&gt;city="SEATTLE";L=LENGTH(CITY); OUTPUT;&lt;BR /&gt;city="BOSTON";L=LENGTH(CITY); OUTPUT;&lt;BR /&gt;city="MIAMI";L=LENGTH(CITY); OUTPUT;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint; SELECT CITY INTO: CITY_list FROM HAVE; QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro LOOP1;&lt;BR /&gt;%local i next_name;&lt;BR /&gt;%do i=1 %to %sysfunc(countw(&amp;amp;CITY_list));&lt;BR /&gt;%let next_name = %scan(&amp;amp;CITY_list, &amp;amp;i);&lt;BR /&gt;data &amp;amp;NEXT_NAME ; SET have ;&lt;BR /&gt;if prxmatch ("/\&amp;amp;NEXT_NAME/", CITY) then flag=1; if flag=1;&lt;BR /&gt;KEEP CITY L;&lt;BR /&gt;RUN;&lt;BR /&gt;%let i = %eval(&amp;amp;i + 1);&lt;BR /&gt;%end;&lt;BR /&gt;%MEND;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LOOP1;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 03:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/813980#M321280</guid>
      <dc:creator>Noomen</dc:creator>
      <dc:date>2022-05-18T03:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP  TROUGH A LIST of STRINGS TO CREATE DIFFERENT FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/813982#M321282</link>
      <description>&lt;P&gt;The initial issue is that you need to use SEPARATED BY in the SQL SELECT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select city into :city_list from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But there are other issues as well.&lt;/P&gt;
&lt;P&gt;Why do you create flag in the data step when you do not keep it?&lt;/P&gt;
&lt;P&gt;And you do not need the macro loop. Define the macro with next_name as parameter, and use CALL EXECUTE in a DATA _NULL_ step from dataset have to call the macro for each city.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 03:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/813982#M321282</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-18T03:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP  TROUGH A LIST of STRINGS TO CREATE DIFFERENT FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/813984#M321284</link>
      <description>&lt;P&gt;Why complicate your macro with a loop? Just call your macro for each city:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyMacro (Next_Name = );

data &amp;amp;NEXT_NAME ; SET have ;
if prxmatch ("/\&amp;amp;NEXT_NAME/", CITY) then flag=1; if flag=1;
KEEP CITY L;
RUN;

%mend MyMacro;

DATA have;
city="TORONTO";L=LENGTH(CITY); OUTPUT;
city="SEATTLE";L=LENGTH(CITY); OUTPUT;
city="BOSTON";L=LENGTH(CITY); OUTPUT;
city="MIAMI";L=LENGTH(CITY); OUTPUT;
RUN;

data _null_;
  set have;
  call execute('%MyMacro (Next_Name =' !! trim(city) !! ')');
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 May 2022 03:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/813984#M321284</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-05-18T03:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP  TROUGH A LIST of STRINGS TO CREATE DIFFERENT FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/814105#M321341</link>
      <description>Thanks but it fails if the city name has a blank (like SAN DIEGO, LOS ANGELES, etc. ).&lt;BR /&gt;What would be the fix in the prxmatch parameters to allow the macro to run ?</description>
      <pubDate>Wed, 18 May 2022 15:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/814105#M321341</guid>
      <dc:creator>Noomen</dc:creator>
      <dc:date>2022-05-18T15:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP  TROUGH A LIST of STRINGS TO CREATE DIFFERENT FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/814150#M321374</link>
      <description>Thanks for your questions. Actually, my real dataset is much more complicated (I work for the Federal Department of Transport), hence the extra variables. I just tried to narrow down the question to the loop I was planning to build..</description>
      <pubDate>Wed, 18 May 2022 18:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/814150#M321374</guid>
      <dc:creator>Noomen</dc:creator>
      <dc:date>2022-05-18T18:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP  TROUGH A LIST of STRINGS TO CREATE DIFFERENT FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/814163#M321382</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/325644"&gt;@Noomen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks but it fails if the city name has a blank (like SAN DIEGO, LOS ANGELES, etc. ).&lt;BR /&gt;What would be the fix in the prxmatch parameters to allow the macro to run ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do NOT use the CITY name as the name of the DATASET.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add some other argument to your macro to specify the name of the dataset to be created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also why are you using regular expressions?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro next(ds=,city=);
data &amp;amp;DS ;
  SET have ;
  where city = "&amp;amp;city";
  ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 May 2022 19:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-TROUGH-A-LIST-of-STRINGS-TO-CREATE-DIFFERENT-FILES/m-p/814163#M321382</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-18T19:29:24Z</dc:date>
    </item>
  </channel>
</rss>

