<?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: How to set a variable filename (INFILE-statement)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395429#M95372</link>
    <description>&lt;P&gt;When you do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile &amp;amp;saslogfile_fullpath firstobs=2 length=linelength;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you reference a macro variable; this reference is resolved &lt;U&gt;once&lt;/U&gt; while the datastep is compiled, and requires the macro variable to be present at that time.&lt;/P&gt;
&lt;P&gt;A code snippet that reads all lines from a bunch of textfiles into a dataset would look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dirlist pipe "ls /sas/prd/common/SASApp_IAM_WorkspaceServer_*.log";

data dirlist;
infile dirlist truncover;
input logfile $200.;
run;

data logtext;
set dirlist;
infilename = logfile;
infile xxx filevar=infilename end=eof truncover;
do until (eof);
  input textline $200.;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Sep 2017 08:52:38 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-09-13T08:52:38Z</dc:date>
    <item>
      <title>How to set a variable filename (INFILE-statement)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395423#M95367</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS Programming (9.3) and I'm struggling with setting a variable filename for the INFILE-statement.&lt;/P&gt;&lt;P&gt;Goal :&lt;/P&gt;&lt;P&gt;I want to treat a list of SAS logfiles. The full path name of the file is retrieved from a newly created dataset (SASLOGS. LOGFILES). This dataset was created by a 'ls' on a UNIX-directory where SAS logs are stored (see step 1 in code snippet).&lt;/P&gt;&lt;P&gt;Problem:&lt;/P&gt;&lt;P&gt;In the INFILE-statement, I don't succeed in retrieving the correct value of the file -&amp;gt; ERROR: Invalid physical name.&lt;/P&gt;&lt;P&gt;Eventhough, the variable 'saslogfile_fullpath' contains the correct path (with ""). See code snippet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code snippet :&lt;/P&gt;&lt;P&gt;/*1. Fill SASLOGS.LOGFILES with all filenames listed in directory*/&lt;BR /&gt;filename dirlist pipe "ls /sas/prd/common/SASApp_IAM_WorkspaceServer_*.log";&lt;BR /&gt;LIBNAME SASLOGS "/sas/prd/data/IAM/SASLOGS";&lt;/P&gt;&lt;P&gt;data SASLOGS.LOGFILES;&lt;BR /&gt;infile dirlist lrecl=200 truncover;&lt;BR /&gt;input file_name $200.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* 2. Use SASLOGS.LOGFILES and handle each file (see value "file_name") seperately*/&lt;BR /&gt;LIBNAME SASLOGS "/sas/prd/data/IAM/SASLOGS";&lt;/P&gt;&lt;P&gt;%let saslogfile_fullpath=' ';&lt;/P&gt;&lt;P&gt;data work.ONE_LOGFILE;&lt;BR /&gt;set SASLOGS.LOGFILES;&lt;BR /&gt;saslogfile_fullpath=trim(file_name);&lt;BR /&gt;saslogfile_fullpath='"' || strip(saslogfile_fullpath) || '"';&lt;BR /&gt;putlog saslogfile_fullpath;/* correct value in&amp;nbsp;&lt;SPAN&gt;saslogfile_fullpath*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;infile &amp;amp;saslogfile_fullpath firstobs=2 length=linelength;&lt;/P&gt;&lt;P&gt;input @1 date YYMMDD10.&lt;BR /&gt;+1 time TIME8.&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/112798"&gt;@24&lt;/a&gt; level $5. @;&lt;/P&gt;&lt;P&gt;lengthSASInfo=linelength-52;&lt;BR /&gt;input @53 SAS_info $VARYING500. lengthSASInfo;&lt;/P&gt;&lt;P&gt;/* call macro to treat logfile*/&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm I doing wrong?&lt;/P&gt;&lt;P&gt;Thanks for your assistance.&lt;/P&gt;&lt;P&gt;Jurgen&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 08:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395423#M95367</guid>
      <dc:creator>jurlis</dc:creator>
      <dc:date>2017-09-13T08:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a variable filename (INFILE-statement)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395428#M95371</link>
      <description>&lt;P&gt;Please share your log, thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your first data step based in your code (which i did too) is working fine. &amp;nbsp;I am not sure about the 2nd data step. &amp;nbsp;I don't know how different the contents of ls command in unix versus dir command in Windows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 08:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395428#M95371</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-13T08:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a variable filename (INFILE-statement)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395429#M95372</link>
      <description>&lt;P&gt;When you do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile &amp;amp;saslogfile_fullpath firstobs=2 length=linelength;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you reference a macro variable; this reference is resolved &lt;U&gt;once&lt;/U&gt; while the datastep is compiled, and requires the macro variable to be present at that time.&lt;/P&gt;
&lt;P&gt;A code snippet that reads all lines from a bunch of textfiles into a dataset would look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dirlist pipe "ls /sas/prd/common/SASApp_IAM_WorkspaceServer_*.log";

data dirlist;
infile dirlist truncover;
input logfile $200.;
run;

data logtext;
set dirlist;
infilename = logfile;
infile xxx filevar=infilename end=eof truncover;
do until (eof);
  input textline $200.;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 08:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395429#M95372</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-13T08:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a variable filename (INFILE-statement)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395445#M95381</link>
      <description>Thanks for pointing me to this option "filevar"! This solved my issue.</description>
      <pubDate>Wed, 13 Sep 2017 09:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-a-variable-filename-INFILE-statement/m-p/395445#M95381</guid>
      <dc:creator>jurlis</dc:creator>
      <dc:date>2017-09-13T09:52:54Z</dc:date>
    </item>
  </channel>
</rss>

