<?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: Why I cant use fixed-width to read data? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-I-cant-use-fixed-width-to-read-data/m-p/787868#M251828</link>
    <description>&lt;P&gt;Why would you used fixed width to read a file that has clear delimiters?&lt;/P&gt;
&lt;P&gt;If you want to separate the temp and blingDays have you tried including multiple delimiters, both the colon and a space in the DLM option? &lt;STRIKE&gt;You'll also want to specify DSD option.&amp;nbsp;&lt;/STRIKE&gt;&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/410569"&gt;@leigao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Use the Data Step to create a SAS dataset based on the information contained in the file. All variables in the SAS dataset should have the numeric&amp;nbsp;data type. The 'gasbill' variable would be missed if I use fixed-width 15-16 for 'bilingDays'. Without using the fixed-width the data would be read correctly. I want to know why this happens.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data gas;
infile 'Database/gas_bills.txt'
dlm=';' truncover;
input 
	date mmddyy10. +1
	temp 2.
	blingDays 15-16
	gasbill dollar16.
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gas;
infile '..gas_bills.txt' dlm = '; ' truncover;
informat date mmddyy. temp blingDays 8. gasbill dollar.;
format date mmddyy. temp blingDays 8. gasbill dollar16.2;
input date temp blingDays gasbill;
run;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Dec 2021 22:54:42 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-12-30T22:54:42Z</dc:date>
    <item>
      <title>Why I cant use fixed-width to read data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-I-cant-use-fixed-width-to-read-data/m-p/787865#M251826</link>
      <description>&lt;P&gt;Use the Data Step to create a SAS dataset based on the information contained in the file. All variables in the SAS dataset should have the numeric&amp;nbsp;data type. The 'gasbill' variable would be missed if I use fixed-width 15-16 for 'bilingDays'. Without using the fixed-width the data would be read correctly. I want to know why this happens.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data gas;
infile 'Database/gas_bills.txt'
dlm=';' truncover;
input 
	date mmddyy10. +1
	temp 2.
	blingDays 15-16
	gasbill dollar16.
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Dec 2021 22:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-I-cant-use-fixed-width-to-read-data/m-p/787865#M251826</guid>
      <dc:creator>leigao</dc:creator>
      <dc:date>2021-12-30T22:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why I cant use fixed-width to read data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-I-cant-use-fixed-width-to-read-data/m-p/787868#M251828</link>
      <description>&lt;P&gt;Why would you used fixed width to read a file that has clear delimiters?&lt;/P&gt;
&lt;P&gt;If you want to separate the temp and blingDays have you tried including multiple delimiters, both the colon and a space in the DLM option? &lt;STRIKE&gt;You'll also want to specify DSD option.&amp;nbsp;&lt;/STRIKE&gt;&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/410569"&gt;@leigao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Use the Data Step to create a SAS dataset based on the information contained in the file. All variables in the SAS dataset should have the numeric&amp;nbsp;data type. The 'gasbill' variable would be missed if I use fixed-width 15-16 for 'bilingDays'. Without using the fixed-width the data would be read correctly. I want to know why this happens.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data gas;
infile 'Database/gas_bills.txt'
dlm=';' truncover;
input 
	date mmddyy10. +1
	temp 2.
	blingDays 15-16
	gasbill dollar16.
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gas;
infile '..gas_bills.txt' dlm = '; ' truncover;
informat date mmddyy. temp blingDays 8. gasbill dollar.;
format date mmddyy. temp blingDays 8. gasbill dollar16.2;
input date temp blingDays gasbill;
run;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 22:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-I-cant-use-fixed-width-to-read-data/m-p/787868#M251828</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-30T22:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why I cant use fixed-width to read data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-I-cant-use-fixed-width-to-read-data/m-p/787874#M251830</link>
      <description>&lt;P&gt;Do not mixed FORMATTED and LIST MODE without knowing what you are doing.&lt;/P&gt;
&lt;P&gt;Just because the file has semi-colons in it does not mean you have to treat it as delimited.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gas;
  infile cards truncover;
  input date mmddyy10.
     +1 temp 2.
     +1 blingDays 2.
     +1 gasbill :comma.
  ;
  format date yymmdd10.;
cards4;
12/29/1999;26 36;$112.72
 1/28/2000;18 30;$95.88
 2/26/2000;24 29;$134.65
 3/25/2000;41 28;$15.32
 4/28/2000;45 34;$47.33
 5/30/2000;60 32;$89.87
 6/24/2000;66 25;$25.55
 7/26/2000;72 32;$8.08
 8/24/2000;72 29;$17.66
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works for your example because the fields are all fixed length.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2021-12-30 180051.jpg" style="width: 337px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67032i635146649E2019B2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2021-12-30 180051.jpg" alt="Screenshot 2021-12-30 180051.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So you could also read them using column mode input , except for fields like DATE and GASBILL that require special informat.&amp;nbsp; For those use formatted mode, you can use&amp;nbsp;@ cursor motion to locate where to start reading GASBILL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  input date mmddyy10.
        temp 12-13
        blingDays 15-16
        @18 gasbill :comma.
  ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could read it as delimited.&amp;nbsp; But since you have two values in one field read that as text and then parse it into the two values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gas;
  infile cards dsd dlm=';' truncover;
  input date :mmddyy. string $ gasbill :comma.;
  temp=input(string,2.);
  blingDays=input(scan(string,2,' '),32.);
  format date yymmdd10.;
  drop string;
cards4;
12/29/1999;26 36;$112.72
 1/28/2000;18 30;$95.88
 2/26/2000;24 29;$134.65
 3/25/2000;41 28;$15.32
 4/28/2000;45 34;$47.33
 5/30/2000;60 32;$89.87
 6/24/2000;66 25;$25.55
 7/26/2000;72 32;$8.08
 8/24/2000;72 29;$17.66
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;                             bling
Obs          date    temp     Days    gasbill

 1     1999-12-29     26       36      112.72
 2     2000-01-28     18       30       95.88
 3     2000-02-26     24       29      134.65
 4     2000-03-25     41       28       15.32
 5     2000-04-28     45       34       47.33
 6     2000-05-30     60       32       89.87
 7     2000-06-24     66       25       25.55
 8     2000-07-26     72       32        8.08
 9     2000-08-24     72       29       17.66
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 23:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-I-cant-use-fixed-width-to-read-data/m-p/787874#M251830</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-30T23:06:01Z</dc:date>
    </item>
  </channel>
</rss>

