<?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: Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915362#M360671</link>
    <description>&lt;P&gt;No problem. Your reply is a good answer also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OCD is not a bad feature for programming.&amp;nbsp; Just make sure it doesn't turn into OWD , Obsessing on the &lt;STRONG&gt;Wrong&lt;/STRONG&gt; Details.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Feb 2024 23:45:06 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-02-09T23:45:06Z</dc:date>
    <item>
      <title>Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915315#M360653</link>
      <description>&lt;P&gt;Hello,&amp;nbsp; I am looking for some suggestions.&amp;nbsp; I'm importing a .csv that has NULL values in numeric fields (using SAS 9.4). I have created the code below based on some google searches.&amp;nbsp; It works fine EXCEPT when I reference nulls in the informat statement, it crops my numeric values to two decimal places.&amp;nbsp; If I try to specify a numeric format (e.g.&amp;nbsp;ConVol nulls. 9.5)&amp;nbsp; I get an error "Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_,&amp;nbsp;_NUMERIC_."&amp;nbsp; I would like to retain all decimal places. And suggestions on how I can modify this code?&amp;nbsp; Thanks in advance!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC FORMAT;&lt;BR /&gt;invalue nulls 'NULL'=. ;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA yield;&lt;BR /&gt;informat&lt;/P&gt;&lt;P&gt;FMAID 2.0&lt;BR /&gt;Model $10.0&lt;BR /&gt;YieldClass 3.0&lt;BR /&gt;ConVol nulls. ;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;infile 'Z:\vol.csv' dsd dlm=',' missover firstobs=2 LRECL=32767 n=500;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input&lt;BR /&gt;FMAID&lt;BR /&gt;Model $&lt;BR /&gt;YieldClass&lt;BR /&gt;ConVol;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Sample Data for reference)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;FMAID&lt;/TD&gt;&lt;TD&gt;Model&lt;/TD&gt;&lt;TD&gt;YieldClass&lt;/TD&gt;&lt;TD&gt;ConVol&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0.74387&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;17.6377&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;36.11641&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;115.1822&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;86.87595&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Vol/Age&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;143.0345&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 09 Feb 2024 18:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915315#M360653</guid>
      <dc:creator>YEGUser</dc:creator>
      <dc:date>2024-02-09T18:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915331#M360655</link>
      <description>&lt;P&gt;Can you show the actual TEXT of the CSV file?&amp;nbsp; You posted something that looks like it was copied from a SPREADSPEET, not a TEXT file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The number of decimal places you SHOW has nothing to do with how you READ in the values.&amp;nbsp; How you PRINT the values is determined by what FORMAT specification you &lt;STRONG&gt;attach&lt;/STRONG&gt; to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your program looks ok, but there some things that are over complicated (or perhaps show a misunderstanding of how SAS works).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you are attaching an INFORMAT to a character variable.&amp;nbsp; Why?&amp;nbsp; SAS already knows how to read in character variables.&amp;nbsp; And why would you specify a number of decimal places on the $ informat??&amp;nbsp; Character strings do not have decimal places.&amp;nbsp; And you only ever need to specify a number of decimal places on a numeric informat when you want SAS to insert the decimal place for you.&amp;nbsp; If the strings being read already have a period in them then that is were the decimal place will be placed.&amp;nbsp; But if the string does not then the number of decimal places specified in the informat tell SAS what power or 10 to use to move the decimal point to the right place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You normally never want to use MISSOVER instead of TRUNCOVER.&amp;nbsp; If you use MISSOVER and instruct the INPUT statement to read more characters than remain on the line then those characters are ignored (set to missing). But if you use TRUNCOVER then it uses the truncated string instead.&amp;nbsp; Since you are using LIST MODE input it does not matter in this particular program since LIST MODE ignores the width specified on the informat and just reads the whole next "word" on the line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your NULLS informat will only recognize NULL in all uppercase.&amp;nbsp; Which from your example might be ok.&amp;nbsp; If you want it to also recognize the string null or Null as a missing value then you should include the UPCASE option when defining it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if you know that any value that does not actually represent a number should be set to missing then you can just not bother with the informat.&amp;nbsp; Instead use the ? or ?? modifier on the INPUT statement to tell it to not generate any errors when it cannot convert the value into a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's assume your actual CSV file looks like this.&amp;nbsp; Let's make a temporary file with your example so we have something to program with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=csv;
filename csv temp;

parmcards4;
FMAID,Model,YieldClass,ConVol
1,Vol/Age,1,0
1,Vol/Age,1,0.74387
1,Vol/Age,1,NULL
1,Vol/Age,1,17.6377
1,Vol/Age,1,36.11641
1,Vol/Age,1,115.1822
1,Vol/Age,1,86.87595
1,Vol/Age,1,NULL
1,Vol/Age,1,143.0345
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to read it just use a data step with:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;INFILE statement using DSD, TRUNCOVER and FIRSTOBS= options.&lt;/LI&gt;
&lt;LI&gt;Define your variables using a LENGTH statement.&lt;/LI&gt;
&lt;LI&gt;Attach any &lt;STRONG&gt;required&lt;/STRONG&gt; FORMAT or INFORMAT to your variables (most variables will need neither).&lt;/LI&gt;
&lt;LI&gt;Attach any LABEL values that you might need (if no label is attached the variable name will be used instead).&lt;/LI&gt;
&lt;LI&gt;INPUT the variables.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;So perhaps something like this (notice the ?? after ConVol on the INPUT statement).&amp;nbsp; Also notice there is no need to add a $ after Model since it was already defined as character when was first seen in the LENGTH statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile csv dsd truncover firstobs=2;
  length FMAID 8 Model $10 YieldClass ConVol 8;
  input FMAID Model YieldClass ConVol ?? ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will print like this:&lt;/P&gt;
&lt;PRE&gt;                           Yield
Obs    FMAID     Model     Class     ConVol

 1       1      Vol/Age      1        0.000
 2       1      Vol/Age      1        0.744
 3       1      Vol/Age      1         .
 4       1      Vol/Age      1       17.638
 5       1      Vol/Age      1       36.116
 6       1      Vol/Age      1      115.182
 7       1      Vol/Age      1       86.876
 8       1      Vol/Age      1         .
 9       1      Vol/Age      1      143.035
&lt;/PRE&gt;
&lt;P&gt;Since PROC PRINT will attempt to find a common number of decimal places that can best display all of the values for a variable on a page.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want ConVol to print with a specific number of decimal places then attach a format.&amp;nbsp; Either in the step that creates it .&amp;nbsp; Or perhaps just in the step that is doing the printing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=want;
  format convol 12.6;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                           Yield
Obs    FMAID     Model     Class          ConVol

 1       1      Vol/Age      1          0.000000
 2       1      Vol/Age      1          0.743870
 3       1      Vol/Age      1           .
 4       1      Vol/Age      1         17.637700
 5       1      Vol/Age      1         36.116410
 6       1      Vol/Age      1        115.182200
 7       1      Vol/Age      1         86.875950
 8       1      Vol/Age      1           .
 9       1      Vol/Age      1        143.034500
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 18:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915331#M360655</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-09T18:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915351#M360667</link>
      <description>&lt;P&gt;Thanks so much for the quick response!&amp;nbsp; A few comments on the reply -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many of us learn from having been handed down code from predecessors. And it's worked and we have continued to follow the template they have set.&amp;nbsp; This is some of the "complexity" you are seeing.&amp;nbsp; There decimal after the informat for character?&amp;nbsp; I'm OCD and I like how it looks, and to date is hasn't cause any problems with the informat, but thank you I'll try to stop doing it.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the trick with the ?? and the note about proc print.&amp;nbsp; I was not aware of this truncation issue with proc print (for some reason I haven't run into it befoe) and it turns out that my original code was doing the job just fine (albeit in a clunky manner!).&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 21:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915351#M360667</guid>
      <dc:creator>YEGUser</dc:creator>
      <dc:date>2024-02-09T21:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915353#M360668</link>
      <description>&lt;P&gt;Apologies - new to this forum.&amp;nbsp; I was trying to accept&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s response as the solution but apparently I failed. Sigh.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 21:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915353#M360668</guid>
      <dc:creator>YEGUser</dc:creator>
      <dc:date>2024-02-09T21:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915362#M360671</link>
      <description>&lt;P&gt;No problem. Your reply is a good answer also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OCD is not a bad feature for programming.&amp;nbsp; Just make sure it doesn't turn into OWD , Obsessing on the &lt;STRONG&gt;Wrong&lt;/STRONG&gt; Details.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 23:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915362#M360671</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-09T23:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915388#M360685</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460485"&gt;@YEGUser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Apologies - new to this forum.&amp;nbsp; I was trying to accept&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s response as the solution but apparently I failed. Sigh.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460485"&gt;@YEGUser&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This has happened to many others before and can be easily corrected:&amp;nbsp;Select Tom's post&amp;nbsp;as the solution after clicking&amp;nbsp;"Not the Solution" in the option menu (see icon below) of the current solution.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="show_option_menu.png" style="width: 155px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93517i61016F34B62492E6/image-size/large?v=v2&amp;amp;px=999" role="button" title="show_option_menu.png" alt="show_option_menu.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2024 10:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915388#M360685</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-02-10T10:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915572#M360756</link>
      <description>LOL - that is my new favourite acronym</description>
      <pubDate>Mon, 12 Feb 2024 14:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915572#M360756</guid>
      <dc:creator>YEGUser</dc:creator>
      <dc:date>2024-02-12T14:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Import - Removing Nulls While Specifying Number of Decimal Places for Remaining Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915573#M360757</link>
      <description>Thank you!</description>
      <pubDate>Mon, 12 Feb 2024 14:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Removing-Nulls-While-Specifying-Number-of-Decimal-Places/m-p/915573#M360757</guid>
      <dc:creator>YEGUser</dc:creator>
      <dc:date>2024-02-12T14:41:02Z</dc:date>
    </item>
  </channel>
</rss>

