<?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: looping through a list to create small dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443820#M111069</link>
    <description>&lt;P&gt;You're mixing macro and data step code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data druglist ;

format drug $200. ;

 ct=countw("&amp;amp;druglist") ;

do i = 1 to ct ;
    drug = scan("&amp;amp;druglist", i) ;
    output ;
end ;

run;

proc print data=druglist;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Mar 2018 16:49:24 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-03-08T16:49:24Z</dc:date>
    <item>
      <title>looping through a list to create small dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443817#M111067</link>
      <description>&lt;P&gt;I want to create a dataset from a list because merging to a proc sql or sql pass through might be easier to manage. I know this must be simple but it doesn't like the scan. &amp;nbsp;The list is separated by commas.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data druglist ;&lt;BR /&gt;format drug $200. ;&lt;BR /&gt;%let ct=%sysfunc(countw(%quote(&amp;amp;druglist.), %str(,) )) ;&lt;BR /&gt;%put &amp;amp;ct. ;&lt;BR /&gt;do i = 1 to &amp;amp;ct ;&lt;BR /&gt;drug = scan(&amp;amp;druglist, i) ;&lt;BR /&gt;output ;&lt;BR /&gt;end ;&lt;BR /&gt;run;&lt;BR /&gt;proc print ; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;24 data druglist ;&lt;BR /&gt;25 format drug $200. ;&lt;BR /&gt;26 %let ct=%sysfunc(countw(%quote(&amp;amp;druglist.), %str(,) )) ;&lt;BR /&gt;27 %put &amp;amp;ct. ;&lt;BR /&gt;6&lt;BR /&gt;28 do i = 1 to &amp;amp;ct ;&lt;BR /&gt;29 drug = scan(&amp;amp;druglist, i) ;&lt;BR /&gt;____&lt;BR /&gt;72&lt;BR /&gt;ERROR 72-185: The SCAN function call has too many arguments.&lt;/P&gt;&lt;P&gt;30 output ;&lt;BR /&gt;31 end ;&lt;BR /&gt;32 run;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 16:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443817#M111067</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2018-03-08T16:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: looping through a list to create small dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443818#M111068</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Double quote the list for macro variable.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data druglist ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;format drug $200. ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%let ct=%sysfunc(countw(%quote(&amp;amp;druglist.), %str(,) )) ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%put &amp;amp;ct. ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;do i = 1 to &amp;amp;ct ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;drug = scan("&amp;amp;druglist", i) ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;proc print ; run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 16:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443818#M111068</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-08T16:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: looping through a list to create small dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443820#M111069</link>
      <description>&lt;P&gt;You're mixing macro and data step code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data druglist ;

format drug $200. ;

 ct=countw("&amp;amp;druglist") ;

do i = 1 to ct ;
    drug = scan("&amp;amp;druglist", i) ;
    output ;
end ;

run;

proc print data=druglist;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Mar 2018 16:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443820#M111069</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-08T16:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: looping through a list to create small dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443826#M111073</link>
      <description>&lt;P&gt;If your "druglist" macro variable has commas then that will cause the error. If your variable has individually quoted values then you'll get a different error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it would help to show what your "druglist" looks like.&lt;/P&gt;
&lt;P&gt;And you are way overusing macro functions where not needed and incorrect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let druglist = a bdq cccccc dddddddddd;
data example ;
do i = 1 to (countw("&amp;amp;druglist"));
   drug = scan("&amp;amp;druglist.", i) ;
   output;
end; ;
run;&lt;/PRE&gt;
&lt;P&gt;You should specify a length for DRUG as otherwise the length is going to be the length of the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 17:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443826#M111073</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-08T17:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: looping through a list to create small dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443829#M111075</link>
      <description>omg - working with too many macros and proc sqls lately I guess. Thank you!</description>
      <pubDate>Thu, 08 Mar 2018 17:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-a-list-to-create-small-dataset/m-p/443829#M111075</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2018-03-08T17:05:22Z</dc:date>
    </item>
  </channel>
</rss>

