<?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: Get structure of a file before importing it into SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598899#M172785</link>
    <description>&lt;P&gt;Even one row is enough.&lt;/P&gt;
&lt;P&gt;Pseudo code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
  infile F dlm=',';
  input;
  call symputx('NB_COLS', countw(_INFILE_,',') );
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Oct 2019 02:52:48 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-10-24T02:52:48Z</dc:date>
    <item>
      <title>Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598891#M172777</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was looking for a way to verify that a file is "correctly" imported into SAS. I have a SAS program that do data steps (with infile) to import data from a .txt or a .csv file. However, the program is running "from a long time" now and I was thinking today : if a new column is added to the file (because many files are produced (aka dumped) automatically by servers), how would I be aware of it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the SAS program specify the position, field name and format, how could I set-up like a "flag" to say &lt;EM&gt;"Hey, there's more column in the file that you set in the infile"&lt;/EM&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TL;DR: Is there a way to get the structure of the file (e.g. number of headers and lines) before importing it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(I don't know if the options GUESSINGROWS=1 is appropriate in this case).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found this post, but I don't understand if it could be a solution to my question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/td-p/506754" target="_self"&gt;https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/td-p/506754&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, thanks in advance for your kindness.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 02:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598891#M172777</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-24T02:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598893#M172779</link>
      <description>&lt;P&gt;Could you just read the first row (with the headers) and count the number of columns?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 02:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598893#M172779</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-24T02:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598897#M172783</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Could you just read the first row (with the headers) and count the number of columns?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Gosh. I was thinking so "out-of-the-box" that I realize, with your reply, how "easy" it could be. My bad (I'm new with SAS).&lt;/P&gt;
&lt;P&gt;Is there a way to specify to SAS to only "infile" the two-first rows?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: I found that I could use the OBS options (e.g. OBS=2). Sorry for the inconveniance&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 02:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598897#M172783</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-24T02:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598899#M172785</link>
      <description>&lt;P&gt;Even one row is enough.&lt;/P&gt;
&lt;P&gt;Pseudo code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
  infile F dlm=',';
  input;
  call symputx('NB_COLS', countw(_INFILE_,',') );
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 02:52:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598899#M172785</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-24T02:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598900#M172786</link>
      <description>&lt;P&gt;Will try it for sure tomorrow moring.&lt;/P&gt;
&lt;P&gt;What is this option ?&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;countw&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 02:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598900#M172786</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-24T02:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598901#M172787</link>
      <description>&lt;P&gt;Various approaches:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename temp temp;

* create csv ;
proc export data=sashelp.class file=temp dbms=csv;
run;

* check csv ;
data _null_;
   infile temp;
   input;
   put _infile_;
run;

* option 1: count delimiters in the header ;
* this assumes there is no edge case of a quoted delimiter in the header ;
data _null_;
   infile temp;
   input;
   call symputx('num_cols',countc(_infile_,',')+1,'G');
   stop;
run;

%put &amp;amp;=num_cols;

* option 2: import the header and count columns ;
proc import file=temp out=class dbms=csv replace;
   getnames=yes;
run;

data _null_;
   if 0 then set class;
   length varname $32;
   do until (varname eq 'varname');
      num_cols+1;
      call vnext(varname);
   end;
   call symputx('num_cols',num_cols-1,'G');
   stop;
run;

%put &amp;amp;=num_cols;

* option 3: dictionary tables ;
* this can have a performance issue if you have a lot of allocated librefs esp. RBDMS ;
proc sql noprint;
   select count(0) into :num_cols trimmed
   from dictionary.columns
   where upcase(libname)='WORK' and upcase(memname)='CLASS';
quit;

%put &amp;amp;=num_cols;

* option 4: proc contents ;
proc contents data=class out=columns (keep=name) noprint;
run;

%let num_cols=%nobs(columns);
%put &amp;amp;=num_cols;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What you do with &amp;amp;num_cols in your downstream code is up to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I once had to do something similar, where I had to read a delimited file created by a web service.&amp;nbsp; The structure could be changed by the customer via a web interface.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that scenario, there was a max number of columns available from the web service, along with known attributes.&amp;nbsp; But the customer could choose a subset, as well as reorder the columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a metadata table in the code via datalines (the metadata was a bit like proc contents output).&amp;nbsp; I used approach #1 to get the list of column names from the header, as well as the order of the columns (a sort column).&amp;nbsp; I then inner joined with the metadata to get the known column attributes and the correct order from the header itself, then generated the correct attrib statements and code to import the dynamic data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH...&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 03:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598901#M172787</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-24T03:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598904#M172789</link>
      <description>&lt;P&gt;Look up this function, it counts words.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 03:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598904#M172789</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-24T03:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598907#M172791</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I once had to do something similar, where I had to read a delimited file created by a web service.&amp;nbsp; The structure could be changed by the customer via a web interface.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that scenario, there was a max number of columns available from the web service, along with known attributes.&amp;nbsp; But the customer could choose a subset, as well as reorder the columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a metadata table in the code via datalines (the metadata was a bit like proc contents output).&amp;nbsp; I used approach #1 to get the list of column names from the header, as well as the order of the columns (a sort column).&amp;nbsp; I then inner joined with the metadata to get the known column attributes and the correct order from the header itself, then generated the correct attrib statements and code to import the dynamic data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
   * reorder columns ;
   format sex name weight height age;
   set sashelp.class;
run;

* create metadata (pretend this was via datalines) ;
proc contents data=sashelp.class out=metadata (keep=name type length label) noprint;
run;

* create a CSV with a subset of the columns ;
data subset / view=subset;
   set class;
   keep name age sex;
run;

filename temp temp;
proc export data=subset file=temp dbms=csv replace;
run;

* get the structure of this csv file ;
data columns;
   length name $32;
   infile temp;
   input;
   do i=1 to countc(_infile_,',')+1;
      name=scan(_infile_,i,',');
      sort+1;
      output;
   end;
   keep name sort;
   stop;
run;

proc sql;
   create table attribs as
   select c.name, m.type, m.length, m.label
   from metadata m
   join columns c
   on upcase(m.name)=upcase(c.name)
   order by c.sort;
quit;

%macro attribs;
%let label=%trim(&amp;amp;label);
attrib &amp;amp;name
length=%if (&amp;amp;type eq 2) %then $&amp;amp;length; %else &amp;amp;length; 
label="&amp;amp;label"
;
%mend;

data final;
   %loop_control(control=attribs,mname=attribs);
   infile temp dlm=',' dsd firstobs=2;
   input (_all_) (:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 03:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/598907#M172791</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-24T03:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599028#M172835</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I once had to do something similar, where I had to read a delimited file created by a web service.&amp;nbsp; The structure could be changed by the customer via a web interface.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that scenario, there was a max number of columns available from the web service, along with known attributes.&amp;nbsp; But the customer could choose a subset, as well as reorder the columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a metadata table in the code via datalines (the metadata was a bit like proc contents output).&amp;nbsp; I used approach #1 to get the list of column names from the header, as well as the order of the columns (a sort column).&amp;nbsp; I then inner joined with the metadata to get the known column attributes and the correct order from the header itself, then generated the correct attrib statements and code to import the dynamic data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
   * reorder columns ;
   format sex name weight height age;
   set sashelp.class;
run;

* create metadata (pretend this was via datalines) ;
proc contents data=sashelp.class out=metadata (keep=name type length label) noprint;
run;

* create a CSV with a subset of the columns ;
data subset / view=subset;
   set class;
   keep name age sex;
run;

filename temp temp;
proc export data=subset file=temp dbms=csv replace;
run;

* get the structure of this csv file ;
data columns;
   length name $32;
   infile temp;
   input;
   do i=1 to countc(_infile_,',')+1;
      name=scan(_infile_,i,',');
      sort+1;
      output;
   end;
   keep name sort;
   stop;
run;

proc sql;
   create table attribs as
   select c.name, m.type, m.length, m.label
   from metadata m
   join columns c
   on upcase(m.name)=upcase(c.name)
   order by c.sort;
quit;

%macro attribs;
%let label=%trim(&amp;amp;label);
attrib &amp;amp;name
length=%if (&amp;amp;type eq 2) %then $&amp;amp;length; %else &amp;amp;length; 
label="&amp;amp;label"
;
%mend;

data final;
   %loop_control(control=attribs,mname=attribs);
   infile temp dlm=',' dsd firstobs=2;
   input (_all_) (:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas" target="_blank" rel="noopener"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas&lt;/A&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I will keep this in my bookmark for further usage. Very useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just open some files dumped by the server and I realize that there's no headers. I take a look at the code (made by someone else) and I realize that field names are user-defined. Since the file do not have any headers, do you think I could use le length of the first line as an indicator of "columns"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By example, the code for loading thoses files looks like :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file1 ;
  infile myfile.txt MISSOVER LRECL = 153 ;
  input
	@1   Field1    10.
	@11  Field2    $15.
	@26  Field3   $1.
	@27  Field4  $1.
	@28  Field5   $2.
	@30  Field6   $6.
	@36  Field7   $60.
	@96  Field8   $2.
	@98  Field9   9.
	@107 Field10   13.
	@120 Field11   11.
	@131 Field12   12.
	@143 Field13   $10.
	@153 Field14  $1.
	@154 Field15  $3.
	;

run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 13:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599028#M172835</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-24T13:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599033#M172838</link>
      <description>&lt;P&gt;For that kind of structure you will probably want to check that the length of the lines is appropriate.&amp;nbsp; For example your posted code is truncating the input lines at 153 bytes and then trying to read data up to byte number 156.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also check key variables to make sure they have valid values. For example FIELD14 might only allow values of 'A' or 'B'.&amp;nbsp; If something else appears in byte number 153 of the line then it is a good indication that the file is not right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: Never use the antiquated MISSOVER option when using formatted input.&amp;nbsp; If your input line had only 155 bytes your input of FIELD15 would be missing, even if bytes 154 and 155 where not blanks.&amp;nbsp; Use the more robust TRUNCOVER option instead.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 13:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599033#M172838</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-24T13:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599133#M172888</link>
      <description>How to check the length of a line?</description>
      <pubDate>Thu, 24 Oct 2019 19:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599133#M172888</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-24T19:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599135#M172889</link>
      <description>&lt;P&gt;There is an INFILE option that will set a variable with the length of the line.&amp;nbsp; You can also test the _INFILE_ automatic variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile 'myfile.txt' length=line_length1 ;
input @;
line_length2=length(_infile_);
line_length3=lengthn(_infile_);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The difference between the two methods is the first one will count any trailing spaces on the line.&amp;nbsp; The difference between the LENGTH() and LENGTHN() functions is when the line only contains blanks.&amp;nbsp; In that case LENGTH() will return 1 and LENGTHN() will return 0.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 19:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599135#M172889</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-24T19:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599136#M172890</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;There is an INFILE option that will set a variable with the length of the line.&amp;nbsp; You can also test the _INFILE_ automatic variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile 'myfile.txt' length=line_length1 ;
input @;
line_length2=length(_infile_);
line_length3=lengthn(_infile_);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The difference between the two methods is the first one will count any trailing spaces on the line.&amp;nbsp; The difference between the LENGTH() and LENGTHN() functions is when the line only contains blanks.&amp;nbsp; In that case LENGTH() will return 1 and LENGTHN() will return 0.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to do this :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
infile myfile.txt truncover;
input @;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it returns no observations, but the obs columns seems to count the total of "lines".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried your code, and it gives me all 155 in both columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I was wondering what the is the usage of this :&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;length&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;line_length1 &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 19:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599136#M172890</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-24T19:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599149#M172895</link>
      <description>Sounds like it did what you asked it to do then.&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Oct 2019 19:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599149#M172895</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-24T19:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599150#M172896</link>
      <description>Yes, a big thanks to you Tom.&lt;BR /&gt;But I don't understand what the length=line_length1 does?</description>
      <pubDate>Thu, 24 Oct 2019 20:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599150#M172896</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-24T20:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: Get structure of a file before importing it into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599152#M172898</link>
      <description>&lt;P&gt;Try it an see.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename junk temp;
data _null_;
  file junk;
  do len=10 to 0 by -1;
     x='12345678901234567890';
     put x $varying10. len ;
  end;
run;

data _null_;
  infile junk length=fred;
  input;
  put _n_= fred= @20 _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;_N_=1 fred=10      1234567890
_N_=2 fred=9       123456789
_N_=3 fred=8       12345678
_N_=4 fred=7       1234567
_N_=5 fred=6       123456
_N_=6 fred=5       12345
_N_=7 fred=4       1234
_N_=8 fred=3       123
_N_=9 fred=2       12
_N_=10 fred=1      1
_N_=11 fred=0
NOTE: 11 records were read from the infile JUNK.
      The minimum record length was 0.
      The maximum record length was 10.&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2019 20:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-structure-of-a-file-before-importing-it-into-SAS/m-p/599152#M172898</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-24T20:11:22Z</dc:date>
    </item>
  </channel>
</rss>

