<?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: infile statement with linelen  ??? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/infile-statement-with-linelen/m-p/937185#M45068</link>
    <description>&lt;P&gt;If you are running anything that looks like&lt;/P&gt;
&lt;PRE&gt;data buildgets ;

/* Read the records containing the name of files to be retrieved from S3                */

infile filelist length=linelen end=eof;
input ObjectName $varying200. linelen;
;
run;&lt;/PRE&gt;
&lt;P&gt;that only has &lt;STRONG&gt;one variable name&lt;/STRONG&gt;, such as Objectname on the Input statement then of course there is only one variable populated.&lt;/P&gt;
&lt;P&gt;IF your data looks&amp;nbsp;&lt;STRONG&gt;exactly&lt;/STRONG&gt; like:&lt;/P&gt;
&lt;PRE&gt;
Path1/MasterList_1.csv

Path2/MasterList_25.csv&lt;/PRE&gt;
&lt;P&gt;then you could use the Infile option dlm='/' and then have two variables on the Input statement. Specify a length long enough to hold the longest expected path.&lt;/P&gt;
&lt;P&gt;But I bet you have edited the "path" to be much shorter and possibly consolidated multiple / used as folder delimiters.&lt;BR /&gt;if that is not the case then state so.&lt;/P&gt;
&lt;P&gt;If not you can use the automatic variable _infile_ and parse the data for the last /&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data example;
  input;
  length path object $ 50 ;
  position= find(_infile_,'/',-100);
  path = substr(_infile_,1,position-1);
  object= substr(_infile_,position+1);
  drop position; 
datalines;
some folder/subfoldername/something.txt
otherfolder/thisfolder/thatfolder/anotherfile.txt
;&lt;/PRE&gt;
&lt;P&gt;You could use code such as your current to read the varying length and us it where I have used _infile_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The use of $Varying and Length option I would expect to see accompanied by more code to parse the input line. The $Varying informat is used when you don't know how long a value might be and Length= option variable, or another variable, provides additional information to help input the value. I see know reason the $varying informat was needed. Most of the reasons behind $varying disappeared with the advent of delimited data but you might find a reason in some file formats where there is a variable that indicates how long as subsequent field might be.&lt;/P&gt;
&lt;P&gt;Here is a totally contrived use of $varying&lt;/P&gt;
&lt;PRE&gt;data example2;
  input fwidth 1. var1 $varying20. fwidth fwidth2 2. var2 $varying20. fwidth2;
datalines;
3abc14this is longer
1z20yetanotherlongerbit&lt;BR /&gt;010abcdefghij&lt;BR /&gt;;&lt;/PRE&gt;
&lt;P&gt;Note the absence of any likely delimiter between values. The first character must be a single digit because of the way the informat is used on the input, that tells SAS how many characters to read with the $varying informat (the second appearance on the Input immediately after $varying to tell SAS how many characters) then a two digit number to specify the number of characters to read of the second variable.&lt;/P&gt;
&lt;P&gt;Please do note the 0 for the&amp;nbsp; third line which means a zero-length string is read, i.e. no value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a similar $varying format that could be used to create such an admittedly obnoxious file construct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data in the source files doesn't exceed about 32K per line you could use the _infile_ option, which attempts to hold the current line of a source file when INPUT executes (with or without variables on the Input statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2024 05:50:04 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-07-26T05:50:04Z</dc:date>
    <item>
      <title>infile statement with linelen  ???</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/infile-statement-with-linelen/m-p/937173#M45067</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to modify / adapt a SAS code that I saw on the web to download many s3 bucket object.&lt;/P&gt;
&lt;P&gt;But in is example, all the object name are save into a text file and are in the same s3 bucket folder which is not my case&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In his example, the text file s3filestodownload.txt contains unique name such as :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;List20.csv&lt;/P&gt;
&lt;P&gt;List55.csv&lt;/P&gt;
&lt;P&gt;List100.csv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;while mine contains also the path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Path1/MasterList_1.csv&lt;/P&gt;
&lt;P&gt;Path2/MasterList_25.csv&lt;/P&gt;
&lt;P&gt;and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The difficulty is I don't perfectly understand the option he is using with the infile statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Heres's the script:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(filelist=);
filename filelist "&amp;amp;filelist";

data buildgets ;

/* Read the records containing the name of files to be retrieved from S3                */

infile filelist length=linelen end=eof;
input ObjectName $varying200. linelen;
;
run;
%mend test;
%test(filelist=/.../info/s3filestodownload.txt);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I am executing his script the dataset buildgets containst only one variable ObjectName&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ObjectName&lt;/P&gt;
&lt;P&gt;Path1/MasterList_1.csv&lt;/P&gt;
&lt;P&gt;Path2/MasterList_25.csv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to have&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Path&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ObjectName&lt;/P&gt;
&lt;P&gt;Path1&amp;nbsp; &amp;nbsp; &amp;nbsp; MasterList_1.csv&lt;/P&gt;
&lt;P&gt;Path2&amp;nbsp; &amp;nbsp; &amp;nbsp;MasterList_25.csv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to adapt his script to obtains the two variables&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that I am not famillar with most of the options he is using, so some explanation will be appreciated&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2024 22:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/infile-statement-with-linelen/m-p/937173#M45067</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-25T22:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: infile statement with linelen  ???</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/infile-statement-with-linelen/m-p/937185#M45068</link>
      <description>&lt;P&gt;If you are running anything that looks like&lt;/P&gt;
&lt;PRE&gt;data buildgets ;

/* Read the records containing the name of files to be retrieved from S3                */

infile filelist length=linelen end=eof;
input ObjectName $varying200. linelen;
;
run;&lt;/PRE&gt;
&lt;P&gt;that only has &lt;STRONG&gt;one variable name&lt;/STRONG&gt;, such as Objectname on the Input statement then of course there is only one variable populated.&lt;/P&gt;
&lt;P&gt;IF your data looks&amp;nbsp;&lt;STRONG&gt;exactly&lt;/STRONG&gt; like:&lt;/P&gt;
&lt;PRE&gt;
Path1/MasterList_1.csv

Path2/MasterList_25.csv&lt;/PRE&gt;
&lt;P&gt;then you could use the Infile option dlm='/' and then have two variables on the Input statement. Specify a length long enough to hold the longest expected path.&lt;/P&gt;
&lt;P&gt;But I bet you have edited the "path" to be much shorter and possibly consolidated multiple / used as folder delimiters.&lt;BR /&gt;if that is not the case then state so.&lt;/P&gt;
&lt;P&gt;If not you can use the automatic variable _infile_ and parse the data for the last /&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data example;
  input;
  length path object $ 50 ;
  position= find(_infile_,'/',-100);
  path = substr(_infile_,1,position-1);
  object= substr(_infile_,position+1);
  drop position; 
datalines;
some folder/subfoldername/something.txt
otherfolder/thisfolder/thatfolder/anotherfile.txt
;&lt;/PRE&gt;
&lt;P&gt;You could use code such as your current to read the varying length and us it where I have used _infile_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The use of $Varying and Length option I would expect to see accompanied by more code to parse the input line. The $Varying informat is used when you don't know how long a value might be and Length= option variable, or another variable, provides additional information to help input the value. I see know reason the $varying informat was needed. Most of the reasons behind $varying disappeared with the advent of delimited data but you might find a reason in some file formats where there is a variable that indicates how long as subsequent field might be.&lt;/P&gt;
&lt;P&gt;Here is a totally contrived use of $varying&lt;/P&gt;
&lt;PRE&gt;data example2;
  input fwidth 1. var1 $varying20. fwidth fwidth2 2. var2 $varying20. fwidth2;
datalines;
3abc14this is longer
1z20yetanotherlongerbit&lt;BR /&gt;010abcdefghij&lt;BR /&gt;;&lt;/PRE&gt;
&lt;P&gt;Note the absence of any likely delimiter between values. The first character must be a single digit because of the way the informat is used on the input, that tells SAS how many characters to read with the $varying informat (the second appearance on the Input immediately after $varying to tell SAS how many characters) then a two digit number to specify the number of characters to read of the second variable.&lt;/P&gt;
&lt;P&gt;Please do note the 0 for the&amp;nbsp; third line which means a zero-length string is read, i.e. no value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a similar $varying format that could be used to create such an admittedly obnoxious file construct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data in the source files doesn't exceed about 32K per line you could use the _infile_ option, which attempts to hold the current line of a source file when INPUT executes (with or without variables on the Input statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 05:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/infile-statement-with-linelen/m-p/937185#M45068</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-26T05:50:04Z</dc:date>
    </item>
  </channel>
</rss>

