<?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: Specifying numeric length when reading in a csv in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Specifying-numeric-length-when-reading-in-a-csv/m-p/567857#M159745</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/275242"&gt;@manonlyn&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric variables in SAS under Windows can have lengths between 3 and 8 bytes. If non-integer values are to be stored, 8 bytes are strongly recommended because shorter lengths come with a loss of precision ("bytes" are &lt;EM&gt;not&lt;/EM&gt;&amp;nbsp;"decimal digits"). Even for small integers variable lengths &amp;lt;8 can be risky (see &lt;A href="https://communities.sas.com/t5/SAS-Procedures/Bug-report-Incorrect-results-from-PROC-SQL-subqueries-working/m-p/415532#M67569" target="_blank" rel="noopener"&gt;this example&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unlike numeric informats, character informats such as $20. define the length of the corresponding variable&amp;nbsp;&lt;EM&gt;if&lt;/EM&gt; it hasn't been defined before (e.g. with a LENGTH statement). For numeric variables you'd need to use the LENGTH statement if you really wanted to define a non-standard length (i.e. &amp;lt;8). Also, note that with modified list input (using the colon modifier as you do) the informat lengths have no impact if they don't define the variable length (see above). So, you can read standard numeric values with &lt;FONT face="courier new,courier"&gt;:1.&lt;/FONT&gt; as well as with &lt;FONT face="courier new,courier"&gt;:32.&lt;/FONT&gt; (or without any informat for that matter), time values such as 12:34:56 PM with &lt;FONT face="courier new,courier"&gt;:time5.&lt;/FONT&gt; as well as with &lt;FONT face="courier new,courier"&gt;:time20.&lt;/FONT&gt; (or with &lt;FONT face="courier new,courier"&gt;:time.&lt;/FONT&gt;, which is &lt;FONT face="courier new,courier"&gt;:time8.&lt;/FONT&gt;) and you can read arbitrary character values with &lt;FONT face="courier new,courier"&gt;:$1.&lt;/FONT&gt;&amp;nbsp;as well as with &lt;FONT face="courier new,courier"&gt;:$123.&lt;/FONT&gt;&amp;nbsp;(or without any informat) if the length of the character variable has been set before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the offset use the @&lt;EM&gt;n&lt;/EM&gt;&amp;nbsp;column pointer control between "INPUT" and the first variable name, e.g.&lt;/P&gt;
&lt;PRE&gt;INPUT &lt;FONT color="#008080"&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;@5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
TENANCY_REFERENCE_NUMBER : $20.
...&lt;/PRE&gt;
&lt;P&gt;to skip the first four bytes of each line.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jun 2019 09:22:51 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-06-21T09:22:51Z</dc:date>
    <item>
      <title>Specifying numeric length when reading in a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specifying-numeric-length-when-reading-in-a-csv/m-p/567853#M159744</link>
      <description>&lt;P&gt;I have to construct a dataset to a specification where the offset and size of a column as well as the type of column is pre-determined.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to force columns to be a certain size when reading them in as a csv using the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA TEST;&lt;BR /&gt;INFILE "C:\Exports to read back in\DATA_AS_CSV.csv" DSD dlm = "," FIRSTOBS = 2 LRECL =2000;&lt;BR /&gt;INPUT&lt;BR /&gt;TENANCY_REFERENCE_NUMBER : $20.&lt;BR /&gt;TRANSACTION1_TYPE : $40.&lt;BR /&gt;TRANSACTION1_AMOUNT : 7.&lt;BR /&gt;TRANSACTION1_DATE : $8.&lt;BR /&gt;TRANSACTION1_DESCRIPTION : $40.&lt;BR /&gt;TRANSACTION1_CD : $1.&lt;BR /&gt;TRANSACTION1_BALANCE : 7.&lt;BR /&gt;TRANSACTION1_RESPONSIBILITY : $10.&lt;BR /&gt;TRANSACTION1_PERIOD : 2.;&lt;BR /&gt;RUN;&lt;/PRE&gt;&lt;P&gt;The main issue I'm having is that all the numerics are reading in as 8 byte fields even though I've tried to specify them being 7 and 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm also not sure how to set the offset. So my dataset specification shows that the data set needs to start at the 5th byte, would anyone be able to advise if this is possible in SAS?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 08:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specifying-numeric-length-when-reading-in-a-csv/m-p/567853#M159744</guid>
      <dc:creator>manonlyn</dc:creator>
      <dc:date>2019-06-21T08:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying numeric length when reading in a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specifying-numeric-length-when-reading-in-a-csv/m-p/567857#M159745</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/275242"&gt;@manonlyn&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric variables in SAS under Windows can have lengths between 3 and 8 bytes. If non-integer values are to be stored, 8 bytes are strongly recommended because shorter lengths come with a loss of precision ("bytes" are &lt;EM&gt;not&lt;/EM&gt;&amp;nbsp;"decimal digits"). Even for small integers variable lengths &amp;lt;8 can be risky (see &lt;A href="https://communities.sas.com/t5/SAS-Procedures/Bug-report-Incorrect-results-from-PROC-SQL-subqueries-working/m-p/415532#M67569" target="_blank" rel="noopener"&gt;this example&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unlike numeric informats, character informats such as $20. define the length of the corresponding variable&amp;nbsp;&lt;EM&gt;if&lt;/EM&gt; it hasn't been defined before (e.g. with a LENGTH statement). For numeric variables you'd need to use the LENGTH statement if you really wanted to define a non-standard length (i.e. &amp;lt;8). Also, note that with modified list input (using the colon modifier as you do) the informat lengths have no impact if they don't define the variable length (see above). So, you can read standard numeric values with &lt;FONT face="courier new,courier"&gt;:1.&lt;/FONT&gt; as well as with &lt;FONT face="courier new,courier"&gt;:32.&lt;/FONT&gt; (or without any informat for that matter), time values such as 12:34:56 PM with &lt;FONT face="courier new,courier"&gt;:time5.&lt;/FONT&gt; as well as with &lt;FONT face="courier new,courier"&gt;:time20.&lt;/FONT&gt; (or with &lt;FONT face="courier new,courier"&gt;:time.&lt;/FONT&gt;, which is &lt;FONT face="courier new,courier"&gt;:time8.&lt;/FONT&gt;) and you can read arbitrary character values with &lt;FONT face="courier new,courier"&gt;:$1.&lt;/FONT&gt;&amp;nbsp;as well as with &lt;FONT face="courier new,courier"&gt;:$123.&lt;/FONT&gt;&amp;nbsp;(or without any informat) if the length of the character variable has been set before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the offset use the @&lt;EM&gt;n&lt;/EM&gt;&amp;nbsp;column pointer control between "INPUT" and the first variable name, e.g.&lt;/P&gt;
&lt;PRE&gt;INPUT &lt;FONT color="#008080"&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;@5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
TENANCY_REFERENCE_NUMBER : $20.
...&lt;/PRE&gt;
&lt;P&gt;to skip the first four bytes of each line.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 09:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specifying-numeric-length-when-reading-in-a-csv/m-p/567857#M159745</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-06-21T09:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying numeric length when reading in a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specifying-numeric-length-when-reading-in-a-csv/m-p/567858#M159746</link>
      <description>&lt;P&gt;What you give the numeric variables in the input statement is just an&amp;nbsp;&lt;I&gt;informat&lt;/I&gt;.&amp;nbsp;This only influences the number of &lt;EM&gt;characters to read&lt;/EM&gt;, but the number variable &lt;EM&gt;storage length&lt;/EM&gt; is still set to the default value of 8. SAS stores numbers in a real format (mantissa, exponent and sign combined into 8 bytes), which allows the storage of very large and very small values, but has a limited precision. If you reduce the length of numeric variables (which is possible), you give up precision, not range.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your first character value starts at position 5, with 4 blanks before that, you do not need to act on that. The $w. informat discards leading blanks.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 09:31:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specifying-numeric-length-when-reading-in-a-csv/m-p/567858#M159746</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-21T09:31:17Z</dc:date>
    </item>
  </channel>
</rss>

