<?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: file name with a variable in a loop in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48865#M13231</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you use PIPE function at SAS? &lt;/P&gt;&lt;P&gt;The following code can get the excel file name you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename x PIPE 'dir K:\place_where_files_go\hb\*.xls /b' ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And libname statement + dictionary can get very sheets name in every excel file .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 30 Mar 2012 04:03:51 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-03-30T04:03:51Z</dc:date>
    <item>
      <title>file name with a variable in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48861#M13227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Moving along.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have this block of code that generates a nice Excel listing file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;LIBNAME MYXLS2 "K:\place_where_files_go\hb\entity.xls";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;PROC DATASETS LIB=MYXLS2;&lt;BR /&gt;DELETE 'data'n;&lt;BR /&gt;RUN;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;proc sql;&lt;BR /&gt;create table myxls2.data as&lt;BR /&gt;&amp;nbsp; select fieldname1, fieldname2, fieldname3, fieldname4&lt;BR /&gt;&amp;nbsp; from table &lt;BR /&gt;&amp;nbsp; where fieldname5='entity';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This gets repeated 44 times- one time for each entity for which an output file is generated.&amp;nbsp; There are 44 entities.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like is something like: &lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;list = some sort of list (array?) of entities&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;for each entity in list&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;LIBNAME MYXLS2 "K:\place_where_files_go\hb\&amp;lt;a variable that changes each time through the loop and is the entity&amp;gt;.xls";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;PROC DATASETS LIB=MYXLS2;&lt;BR /&gt;DELETE 'data'n;&lt;BR /&gt;RUN;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;proc sql;&lt;BR /&gt;create table myxls2.data as&lt;BR /&gt;&amp;nbsp; select fieldname1, fieldname2, fieldname3, fieldname4&lt;BR /&gt;&amp;nbsp; from table &lt;BR /&gt;&amp;nbsp; where fieldname5='&amp;lt;the entity variable again&amp;gt;';&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;next entity&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so that I don't have to repeat the code block a gazillion times. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is such a thing possible?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 20:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48861#M13227</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2012-03-29T20:09:59Z</dc:date>
    </item>
    <item>
      <title>file name with a variable in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48862#M13228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; you only need to change the highlighted part?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: 'Arial','sans-serif'; color: #333333; font-size: 10pt;"&gt;where fieldname5='&amp;lt;&lt;/SPAN&gt;&lt;SPAN lang="EN" style="font-family: 'Arial','sans-serif'; color: red; font-size: 10pt;"&gt;the entity variable again&lt;/SPAN&gt;&lt;SPAN lang="EN" style="font-family: 'Arial','sans-serif'; color: #333333; font-size: 10pt;"&gt;&amp;gt;';&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 20:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48862#M13228</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-03-29T20:26:27Z</dc:date>
    </item>
    <item>
      <title>file name with a variable in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48863#M13229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No the code block generating the excel file would need to change in 2 places.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One- the name of the file outputted.&amp;nbsp; First time through the loop it might be fred.xls, second time through jane.xls, third time through george.xls&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;K:\place_where_files_go\hb\&amp;lt;a variable that changes each time through the loop and is the entity&amp;gt;.xls";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Two the SQL woudl change. Where fieldname5="fred", Where fieldname5="jane", Where fieldname5="george" and so on &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was thinking this might somehow work from a listing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;names="fred,jane,george"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 21:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48863#M13229</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2012-03-29T21:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: file name with a variable in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48864#M13230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thy this one. (not tested)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let names=fred jane george;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%do i=1 %to %sysfunc(countw(&amp;amp;names));&lt;/P&gt;&lt;P&gt;%let var=%sysfunc(scan(&amp;amp;names,&amp;amp;i));&lt;/P&gt;&lt;P&gt;LIBNAME MYXLS2 "K:\place_where_files_go\hb\&amp;amp;var..xls";&lt;/P&gt;&lt;P&gt;PROC DATASETS LIB=MYXLS2;&lt;/P&gt;&lt;P&gt;DELETE 'data'n;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table myxls2.data as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select fieldname1, fieldname2, fieldname3, fieldname4&lt;/P&gt;&lt;P&gt;&amp;nbsp; from table&amp;nbsp; ??? &lt;/P&gt;&lt;P&gt;&amp;nbsp; where upcase(fieldname5)="%upcase(&amp;amp;var)";&lt;/P&gt;&lt;P&gt; quit;&lt;/P&gt;&lt;P&gt; libname MYXLS2 clear;&lt;/P&gt;&lt;P&gt; %end;&lt;/P&gt;&lt;P&gt; %mend;&lt;/P&gt;&lt;P&gt; %test&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 22:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48864#M13230</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-03-29T22:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: file name with a variable in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48865#M13231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you use PIPE function at SAS? &lt;/P&gt;&lt;P&gt;The following code can get the excel file name you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename x PIPE 'dir K:\place_where_files_go\hb\*.xls /b' ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And libname statement + dictionary can get very sheets name in every excel file .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 04:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48865#M13231</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-03-30T04:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: file name with a variable in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48866#M13232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Linlin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that is your untested code, I don't want to be around when you break out the weapons grade fully tested stuff.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That worked first time first run out of the box.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input junkname $;&lt;BR /&gt;datalines;&lt;BR /&gt;jane&lt;BR /&gt;bob&lt;BR /&gt;danny&lt;BR /&gt;fred&lt;BR /&gt;wilbur&lt;BR /&gt;george&lt;BR /&gt;jorge&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let names=fred jane george;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test;&lt;BR /&gt;%do i=1 %to %sysfunc(countw(&amp;amp;names));&lt;BR /&gt;%let var=%sysfunc(scan(&amp;amp;names,&amp;amp;i));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LIBNAME MYXLS2 "K:\fileplace\&amp;amp;var..xls";&lt;BR /&gt;PROC DATASETS LIB=MYXLS2;&lt;BR /&gt;DELETE 'data'n;&lt;BR /&gt;RUN;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table myxls2.data as&lt;BR /&gt;&amp;nbsp; select junkname&lt;BR /&gt;&amp;nbsp; from have &lt;BR /&gt;&amp;nbsp; where upcase(junkname)="%upcase(&amp;amp;var)";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname MYXLS2 clear;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Created 3 xls files off of the SQL slicker than some new military substance engineered to be super slick.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 14:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/file-name-with-a-variable-in-a-loop/m-p/48866#M13232</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2012-03-30T14:39:12Z</dc:date>
    </item>
  </channel>
</rss>

