<?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 Reading an input file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491089#M128697</link>
    <description>&lt;P&gt;hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a text&amp;nbsp; file which contain records like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file have header with table name ,physical name ,descripition ,type all the records are seprtaed by a delimliter #&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;description is mentioned in multiple lines&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tablename,physical_name,descripition,type&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;T1#customer_data# this is a customer&lt;BR /&gt;table with different data&lt;BR /&gt;and records which is used&lt;BR /&gt;for extraction&lt;BR /&gt;#char&lt;BR /&gt;T2#accounts# this is account information&lt;BR /&gt;which contain accout number and&lt;BR /&gt;account details as well&lt;BR /&gt;as other&lt;BR /&gt;information#char&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to create a dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;table, physical name,description and type&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I read this file&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Aug 2018 05:09:10 GMT</pubDate>
    <dc:creator>shubham1</dc:creator>
    <dc:date>2018-08-30T05:09:10Z</dc:date>
    <item>
      <title>Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491089#M128697</link>
      <description>&lt;P&gt;hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a text&amp;nbsp; file which contain records like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file have header with table name ,physical name ,descripition ,type all the records are seprtaed by a delimliter #&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;description is mentioned in multiple lines&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tablename,physical_name,descripition,type&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;T1#customer_data# this is a customer&lt;BR /&gt;table with different data&lt;BR /&gt;and records which is used&lt;BR /&gt;for extraction&lt;BR /&gt;#char&lt;BR /&gt;T2#accounts# this is account information&lt;BR /&gt;which contain accout number and&lt;BR /&gt;account details as well&lt;BR /&gt;as other&lt;BR /&gt;information#char&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to create a dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;table, physical name,description and type&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I read this file&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 05:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491089#M128697</guid>
      <dc:creator>shubham1</dc:creator>
      <dc:date>2018-08-30T05:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491095#M128703</link>
      <description>&lt;P&gt;Please show us an example of what the text data&amp;nbsp;&lt;STRONG&gt;actually&lt;/STRONG&gt; looks like (alter the values if needed).&lt;/P&gt;
&lt;P&gt;Use the {i} icon to paste a couple of example records.&lt;/P&gt;
&lt;P&gt;Also show what the expected output looks like for these 2 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 05:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491095#M128703</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-30T05:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491098#M128704</link>
      <description>&lt;P&gt;this is how dataset look like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 794px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22867i84177227BA487E64/image-dimensions/794x41?v=v2" width="794" height="41" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 05:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491098#M128704</guid>
      <dc:creator>shubham1</dc:creator>
      <dc:date>2018-08-30T05:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491099#M128705</link>
      <description>&lt;P&gt;Please re-read &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;'s post carefully and thoroughly, and act accordingly. Do NOT post data in pictures. Expecting us to type data off pictures into code is thoughtless at best, but usually considered a sign of laziness, being impolite or plain rude.&lt;/P&gt;
&lt;P&gt;If you need help, help us in helping you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127952"&gt;@shubham1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;this is how dataset look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 794px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22867i84177227BA487E64/image-dimensions/794x41?v=v2" width="794" height="41" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491099#M128705</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-30T06:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491103#M128707</link>
      <description>&lt;P&gt;this is how I want output to look like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;table_name physical_name descripition type&lt;/STRONG&gt;&lt;BR /&gt;T1,customer_data,this is a customer table with different dataand records which is used for extraction,char&lt;BR /&gt;T2,accounts,this is account information which contain accout number and account details as well as other information,char&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491103#M128707</guid>
      <dc:creator>shubham1</dc:creator>
      <dc:date>2018-08-30T06:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491105#M128708</link>
      <description>&lt;P&gt;So your external file has this layout:&lt;/P&gt;
&lt;PRE&gt;T1,customer_data,this is a customer table with different dataand records which is used for extraction,char
T2,accounts,this is account information which contain accout number and account details as well as other information,char&lt;/PRE&gt;
&lt;P&gt;Note how posting text with the {i} icon works. Fixed font, and no possible conversion of special characters.&lt;/P&gt;
&lt;P&gt;Try this code for reading it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile cards dlm=',';
input
  tablename :$2.
  physical_name :$32.
  description :$200.
  type :$10.
;
cards;
T1,customer_data,this is a customer table with different dataand records which is used for extraction,char
T2,accounts,this is account information which contain accout number and account details as well as other information,char
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note how code posted with the little running man icon looks like. Almost like in the SAS enhanced editor.&lt;/P&gt;
&lt;P&gt;For your practical purpose, remove the cards; section and replace the cards keyword with the physical filename of yout infile.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491105#M128708</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-30T06:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491107#M128710</link>
      <description>&lt;P&gt;I am having an txt file which looks like this&amp;nbsp; where records are seprated by # and i want these records to come in four variable in SAS dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;table_name,physical_name,descripition and type .In the text file records are starting from line 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tablename,physical_name,descripition,type&lt;/P&gt;&lt;P&gt;T1#customer_data# this is a customer&lt;BR /&gt;table with different data&lt;BR /&gt;and records which is used&lt;BR /&gt;for extraction&lt;BR /&gt;#char&lt;BR /&gt;T2#accounts# this is account information&lt;BR /&gt;which contain accout number and&lt;BR /&gt;account details as well&lt;BR /&gt;as other&lt;BR /&gt;information#char&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want this txt file to come into a SAS dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table_name physical_name descripition type&lt;BR /&gt;T1,customer_data,this is a customer table with different data and records which is used for extraction,char&lt;BR /&gt;T2,accounts,this is account information which contain account number and account details as well as other information,char&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491107#M128710</guid>
      <dc:creator>shubham1</dc:creator>
      <dc:date>2018-08-30T06:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491109#M128712</link>
      <description>&lt;P&gt;Please post the text file AS IS into a window opened with the {i} icon. I won't give any further answers before you do this.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491109#M128712</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-30T06:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491114#M128716</link>
      <description>&lt;PRE&gt;tablename,physical_name,descripition,type

T1#customer_data# this is a customer
table with different data
and records which is used
for extraction
#char
T2#accounts# this is account information
which contain accout number and
account details as well
as other
information#char&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Aug 2018 07:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491114#M128716</guid>
      <dc:creator>shubham1</dc:creator>
      <dc:date>2018-08-30T07:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491115#M128717</link>
      <description>&lt;P&gt;If you have line breaks within data that should be a single column, you need to remove these first.&lt;/P&gt;
&lt;P&gt;SAS will act on line breaks BEFORE it acts on delimiters, thereby scrambling your file layout.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Searching here on the communities for "line breaks in variables" found me this (currently the 7th hit): &lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Carriage-Return-Multiple-Line-Break-Issue-Importing-TXT-File/m-p/420988/highlight/true#M52586" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/Carriage-Return-Multiple-Line-Break-Issue-Importing-TXT-File/m-p/420988/highlight/true#M52586&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;It has a solution for a similar issue, although the deilimiters are pipes instead of hash signs.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 07:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491115#M128717</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-30T07:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491132#M128726</link>
      <description>&lt;P&gt;i am not getting how can i use the code that is present in this link to read my txt file&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Carriage-Return-Multiple-Line-Break-Issue-Importing-TXT-File/m-p/420988/highlight/true#M52586" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/Carriage-Return-Multiple-Line-Break-Issue-Importing-TXT-File/m-p/420988/highlight/true#M52586&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 08:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491132#M128726</guid>
      <dc:creator>shubham1</dc:creator>
      <dc:date>2018-08-30T08:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491144#M128734</link>
      <description>&lt;P&gt;I created a file in my sascommunity test directory with these contents:&lt;/P&gt;
&lt;PRE&gt;tablename,physical_name,descripition,type

T1#customer_data# this is a customer
table with different data
and records which is used
for extraction
#char
T2#accounts# this is account information
which contain accout number and
account details as well
as other
information#char&lt;/PRE&gt;
&lt;P&gt;I then used this code from the link I gave you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename sample '$HOME/sascommunity/shubham.txt';

filename fixed '$HOME/sascommunity/shubham_f.txt';

data _null_;
  retain maxp 3 p 0;
  infile sample firstobs=3;
  file fixed ;
  input ;
  if p then put ' ' @;
  put _infile_ @;
  p+countc(_infile_,'#');
  
  if p&amp;gt;= maxp then do ;
    put ;
    p=0;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that there are only four alterations:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;the output file is not temporary&lt;/LI&gt;
&lt;LI&gt;the number of expected delimiters is fixed (in the retain statement)&lt;/LI&gt;
&lt;LI&gt;the statement determining the maximum number of delimiters in _n_=1 has been removed&lt;/LI&gt;
&lt;LI&gt;the delimiter has been changed to the hash sign&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;After that, I ran the following import:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile fixed dlm='#' truncover;
input
  tablename :$2.
  physical_name :$32.
  description :$200.
  type :$10.
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is how the resulting dataset looks like:&lt;/P&gt;
&lt;PRE&gt;T1	customer_data	this is a customer table with different data and records which is used for extraction	char
T2	accounts	this is account information which contain accout number and account details as well as other information	char&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 09:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491144#M128734</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-30T09:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an input file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491159#M128745</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
file 'c:\temp\t.txt';
put 'tablename,physical_name,descripition,type  ';
put '                                             ';
put 'T1#customer_data# this is a customer         ';
put 'table with different data                    ';
put 'and records which is used                    ';
put 'for extraction                               ';
put '#char                                        ';
put 'T2#accounts# this is account information     ';
put 'which contain accout number and              ';
put 'account details as well                      ';
put 'as other                                     ';
put 'information#char                             ';
run;

data tt;
  infile 'c:\temp\t.txt' firstobs=3;
  input ;                  
  retain DATASET NAME DESC;
  length DATASET NAME DESC $200;
  if countc(_infile_,'#')=2 then do;
    DATASET=scan(_infile_,1,'#');
    NAME   =scan(_infile_,2,'#');
    DESC   =scan(_infile_,3,'#');
  end;
  else if _infile_ ne '#char' then DESC=catx(' ',DESC,scan(_infile_,1,'#'));
  if index(_infile_, '#char') then output;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;DATASET&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;NAME&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;DESC&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;T1&lt;/TD&gt;
&lt;TD class="l data"&gt;customer_data&lt;/TD&gt;
&lt;TD class="l data"&gt;this is a customer table with different data and records which is used for extraction&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;T2&lt;/TD&gt;
&lt;TD class="l data"&gt;accounts&lt;/TD&gt;
&lt;TD class="l data"&gt;this is account information which contain accout number and account details as well as other information&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide complete and clear explanation in your first post next time, and fully answer the questions asked. Don't make it hard to help you.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 10:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-input-file/m-p/491159#M128745</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-30T10:39:53Z</dc:date>
    </item>
  </channel>
</rss>

