<?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: Macrotizing file name in infile file reference in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569165#M160353</link>
    <description>&lt;P&gt;filename zip1 zip "&amp;amp;dir./&amp;amp;file..zip";&lt;BR /&gt;filename ds "%sysfunc(getoption(work))/test.sas7bdat";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Read the "members" (files) from the ZIP file */&lt;BR /&gt;data contents (keep=memname isfolder);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; length memname $200 isfolder 8;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; fid=dopen("zip1");&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if fid=0 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stop;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; memcount=dnum(fid);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; do i=1 to memcount;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; memname=dread(fid,i);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; isFolder = (first(reverse(trim(memname)))='/');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; rc=dclose(fid);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; set contents;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if index(memname, "arc") &amp;gt; 0 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call symput('fname', memname);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; infile zip1(&amp;amp;fname)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lrecl=256 recfm=F length=length eof=eof unbuf;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; file ds lrecl=256 recfm=N;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; input;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; put _infile_ $varying256. length;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; return;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; eof:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; stop;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jun 2019 16:58:16 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2019-06-26T16:58:16Z</dc:date>
    <item>
      <title>Macrotizing file name in infile file reference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569156#M160345</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having a very strange problem. I have a program which refers to a zip file using a filename statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename zip1 zip "&amp;amp;dir./&amp;amp;file..zip";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then later, I try to read in a SAS file from within the zip file using the infile statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; infile zip1(C:/dirname/filename.sas7bdat)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lrecl=256 recfm=F length=length eof=eof unbuf;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;-other unrelated stuff-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works just fine. The issue is that I wanted to automatically generate the name of the SAS file. I set up a step to do this and it produces exactly the value I wanted (C:/dirname/filename.sas7bdat).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is that the data _null_ step above will work if I use the value of the macro variable written out (C:/dirname/filename.sas7bdat), but will generate an error message if I substitute that with &amp;amp;macrovar. I tried putting " " around &amp;amp;macrovar (no help), and macrotizing just parts of the filepath (which worked fine, but I want to macrotize the whole thing).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error message I get says that the SAS file does not exist within the zip file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 16:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569156#M160345</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2019-06-26T16:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macrotizing file name in infile file reference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569158#M160347</link>
      <description>Show your code that isn't working.</description>
      <pubDate>Wed, 26 Jun 2019 16:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569158#M160347</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-26T16:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macrotizing file name in infile file reference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569165#M160353</link>
      <description>&lt;P&gt;filename zip1 zip "&amp;amp;dir./&amp;amp;file..zip";&lt;BR /&gt;filename ds "%sysfunc(getoption(work))/test.sas7bdat";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Read the "members" (files) from the ZIP file */&lt;BR /&gt;data contents (keep=memname isfolder);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; length memname $200 isfolder 8;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; fid=dopen("zip1");&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if fid=0 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stop;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; memcount=dnum(fid);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; do i=1 to memcount;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; memname=dread(fid,i);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; isFolder = (first(reverse(trim(memname)))='/');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; rc=dclose(fid);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; set contents;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if index(memname, "arc") &amp;gt; 0 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call symput('fname', memname);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; infile zip1(&amp;amp;fname)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lrecl=256 recfm=F length=length eof=eof unbuf;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; file ds lrecl=256 recfm=N;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; input;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; put _infile_ $varying256. length;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; return;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; eof:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; stop;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 16:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569165#M160353</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2019-06-26T16:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macrotizing file name in infile file reference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569177#M160362</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    set contents;
    if index(memname, "arc") &amp;gt; 0 then
        call symputx('fname', memname);
run;

%put &amp;amp;fname;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you run the following and post the log- note the change to call symputX - adding X.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 17:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569177#M160362</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-26T17:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macrotizing file name in infile file reference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569178#M160363</link>
      <description>&lt;P&gt;Since your problem seems to be with the first statement of that code, the rest is irrelevant. What's really important is the code that creates the two macro variables &amp;amp;dir and &amp;amp;file. Please show us that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if your problem happens later here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    set contents;
    if index(memname, "arc") &amp;gt; 0 then
        call symput('fname', memname);
run;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you should use call symputx, as it trims leading and trailing blanks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set contents;
if index(memname, "arc") &amp;gt; 0
then call symputx('fname', memname);
run;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this will get you only the&amp;nbsp;&lt;EM&gt;last&lt;/EM&gt; entry in contents that satisfies the condition.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 17:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrotizing-file-name-in-infile-file-reference/m-p/569178#M160363</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-26T17:30:07Z</dc:date>
    </item>
  </channel>
</rss>

