<?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: Replace _NULL_ values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443306#M110894</link>
    <description>&lt;P&gt;Read into character, and do a conditional conversion:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PROBLEM_SET;
format ID $2. VAR1 $4. VAR2 8. VAR3 $10.;
format VALID_FROM VALID_TO  Date9.;
input     @1  ID  
        @3    VAR1  
        @8  VAR2  
        @10 _VALID_FROM $
        @17 _VALID_TO $
		@26 VAR3
;
if _VALID_FROM ne '_NULL_' then VALID_FROM = input(_VALID_FROM,best.);
if _VALID_TO ne '_NULL_' then VALID_TO = input(_VALID_TO,best.);
drop _VALID_FROM _VALID_TO;
datalines;
AB xxxx 1 _NULL_ 17897   test1
AB xxxx 1 17898  18262   test2
AB xxxx 1 18263  18627   _NULL_
AB xxxx 1 18628  _NULL_  test3
AB xxxx 1 _NULL_ 19272   _NULL_

;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Mar 2018 14:09:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-03-07T14:09:54Z</dc:date>
    <item>
      <title>Replace _NULL_ values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443303#M110893</link>
      <description>&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there anybody out there who knows how to cope with variable values which are "_NULL_":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PROBLEM_SET;
format ID $2. VAR1 $4. VAR2 8. VAR3 $10.;
format VALID_FROM VALID_TO  Date9.;
input     @1  ID  
        @3    VAR1  
        @8  VAR2  
        @10 VALID_FROM 
        @17 VALID_TO
		@26 VAR3
;
datalines;
AB xxxx 1 _NULL_ 17897   test1
AB xxxx 1 17898  18262   test2
AB xxxx 1 18263  18627   _NULL_
AB xxxx 1 18628  _NULL_  test3
AB xxxx 1 _NULL_ 19272   _NULL_

;
run;



data HAVE;
format ID $2. VAR1 $4. VAR2 8. VAR3 $10.;
format VALID_FROM VALID_TO  Date9.;
input     @1  ID  
        @3    VAR1  
        @8  VAR2  
        @10 VALID_FROM 
        @17 VALID_TO
		@26 VAR3 
;
datalines;
AB xxxx 1 .      17897   test1
AB xxxx 1 17898  18262   test2
AB xxxx 1 18263  18627   _NULL_
AB xxxx 1 18628  .       test3
AB xxxx 1 .      19272   _NULL_

;
RUN;

data WANT;
set HAVE;
if VAR3 eq "_NULL_" then VAR3 = "";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you can see, therre are numeric and alphanumeric _NULL_-values in the PROBLEM DATASET, which I want to be adequately replace (meaning: alphanumeric values transform to " " and numeric values to ".").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using PROC IMPORT I always get errors b/c SAS detects for examle a string, namely the word "_NULL_" in a numeric variable....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be very much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FK1&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 14:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443303#M110893</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2018-03-07T14:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Replace _NULL_ values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443306#M110894</link>
      <description>&lt;P&gt;Read into character, and do a conditional conversion:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PROBLEM_SET;
format ID $2. VAR1 $4. VAR2 8. VAR3 $10.;
format VALID_FROM VALID_TO  Date9.;
input     @1  ID  
        @3    VAR1  
        @8  VAR2  
        @10 _VALID_FROM $
        @17 _VALID_TO $
		@26 VAR3
;
if _VALID_FROM ne '_NULL_' then VALID_FROM = input(_VALID_FROM,best.);
if _VALID_TO ne '_NULL_' then VALID_TO = input(_VALID_TO,best.);
drop _VALID_FROM _VALID_TO;
datalines;
AB xxxx 1 _NULL_ 17897   test1
AB xxxx 1 17898  18262   test2
AB xxxx 1 18263  18627   _NULL_
AB xxxx 1 18628  _NULL_  test3
AB xxxx 1 _NULL_ 19272   _NULL_

;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Mar 2018 14:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443306#M110894</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-07T14:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Replace _NULL_ values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443397#M110927</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114220"&gt;@FK1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi everybody,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there anybody out there who knows how to cope with variable values which are "_NULL_":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, therre are numeric and alphanumeric _NULL_-values in the PROBLEM DATASET, which I want to be adequately replace (meaning: alphanumeric values transform to " " and numeric values to ".").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When using PROC IMPORT I always get errors b/c SAS detects for examle a string, namely the word "_NULL_" in a numeric variable....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be very much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FK1&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Actually the issue could well be that you are relying on a guessing procedure to handle a systemic issue. After the first time you should have know that you have this issue with _null_ and addressed that.&lt;/P&gt;
&lt;P&gt;If the files you are importing are of the same layout then a data step to read the code would allow you use custom informats and clean that garbage up at read time.&lt;/P&gt;
&lt;PRE&gt;proc format lib=work ;
invalue probnum
'_NULL_'=.
;
invalue $probchar
'_NULL_'=' '
;
run;
data PROBLEM_SET;
format ID $2. VAR1 $4. VAR2 8. VAR3 $10.;
informat  VALID_FROM VALID_TO  probnum. var3 probchar.;
format VALID_FROM VALID_TO  Date9.;
input    @1  ID  
        @3    VAR1  
        @8  VAR2  
        @10 VALID_FROM 
        @17 VALID_TO
		  @26 VAR3
;
datalines;
AB xxxx 1 _NULL_ 17897   test1
AB xxxx 1 17898  18262   test2
AB xxxx 1 18263  18627   _NULL_
AB xxxx 1 18628  _NULL_  test3
AB xxxx 1 _NULL_ 19272   _NULL_

;
run;
&lt;/PRE&gt;
&lt;P&gt;You don't mention the type of file you are importing. If it is a delimited file you can use proc import to generate the skeleton code and then modify it as needed. Copy from the log and paste into the editor, change and save. Change infile statement and data set name for other files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 16:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443397#M110927</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-07T16:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Replace _NULL_ values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443509#M110961</link>
      <description>&lt;P&gt;One way to deal with this is to make your own formats that understand how to treat the string _NULL_.&lt;/P&gt;
&lt;P&gt;Something like this would work for your example data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
invalue null '_NULL_','_null_' = . other=_same_;
invalue $null '_NULL_','_null_' = ' ' other=_same_ ;
run;

data PROBLEM_SET;
length ID $2 VAR1 $4 VAR2 8 VALID_FROM VALID_TO 8 VAR3 $10;
format VALID_FROM VALID_TO  Date9.;
input (ID -- VAR3) (:null.) ;
datalines;
AB xxxx 1 _NULL_ 17897   test1
AB xxxx 1 17898  18262   test2
AB xxxx 1 18263  18627   _NULL_
AB xxxx 1 18628  _NULL_  test3
AB xxxx 1 _NULL_ 19272   _NULL_
;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS There is no need to attach $xx. formats to character variables. SAS already knows how to print character variables (and numbers too).&amp;nbsp; Use the LENGTH or ATTRIB function if you want to define your variables instead of forcing SAS to define them as a side effect of using having a FORMAT statement be the first place your variable is mentioned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 21:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443509#M110961</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-07T21:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Replace _NULL_ values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443729#M111036</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;thanks a lot, for this elegant solution. Also, thanks for the elaboration on the LENGTH / FORMAT statement.&lt;BR /&gt;I do have a follow-up question, however:&lt;BR /&gt;Am I assuming correct, that this line of your code&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input (ID -- VAR4) (:null.) ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;assigns the created invlaue checks ("null" and "$null")?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How does SAS know when to use the invalue-check without the $ sign for numbers variables and when to use the one with the $ sign for the character variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 12:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443729#M111036</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2018-03-08T12:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Replace _NULL_ values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443753#M111041</link>
      <description>&lt;P&gt;It is a "feature" of SAS.&amp;nbsp; If you use the wrong type of format/informat SAS just fixes it for you.&amp;nbsp; Mainly in PUT/INPUT statements I think.&lt;/P&gt;
&lt;PRE&gt;2646  data _null_;
2647    set sashelp.class (obs=2);
2648    put name best. ;
                 -----
                 484
NOTE 484-185: Format $BEST was not found or could not be loaded.

2649  run;

Alfred
Alice
NOTE: There were 2 observations read from the data set SASHELP.CLASS.
&lt;/PRE&gt;
&lt;P&gt;By naming the formats the same, except for the $ prefix, I was able to take advantage of it.&lt;/P&gt;
&lt;P&gt;In your real program you would probably want to use the right format for each specific variable.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 13:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-NULL-values/m-p/443753#M111041</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-08T13:50:33Z</dc:date>
    </item>
  </channel>
</rss>

