<?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: Unable to replace replace missing data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427294#M68437</link>
    <description>&lt;P&gt;Is N_CYL a char type variable?&lt;/P&gt;
&lt;P&gt;If positive then you nead check for 'NA' instead just NA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is numeric with a format, check what code displayes NA ?&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2018 17:35:54 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2018-01-12T17:35:54Z</dc:date>
    <item>
      <title>Unable to replace replace missing data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427291#M68436</link>
      <description>&lt;P&gt;I have been trying to replace the observations which had "NA " in their place with some value ; but what ever I do the value at those points remain "NA"&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT DATAFILE="/folders/myfolders/cars.xls"
	DBMS=XLS
	OUT=WORK.cars_2;
	GETNAMES=YES;
RUN;

data xx;
set cars_2;
if n_cyl=NA then n_cyl=4;		*NOT WORKING; 
if luggage=NA then luggage=9;
run;
proc print data=xx;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jan 2018 17:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427291#M68436</guid>
      <dc:creator>Sai_Sampath</dc:creator>
      <dc:date>2018-01-12T17:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to replace replace missing data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427294#M68437</link>
      <description>&lt;P&gt;Is N_CYL a char type variable?&lt;/P&gt;
&lt;P&gt;If positive then you nead check for 'NA' instead just NA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is numeric with a format, check what code displayes NA ?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 17:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427294#M68437</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-01-12T17:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to replace replace missing data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427296#M68438</link>
      <description>&lt;P&gt;right on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;, neat catch. I am just wondering why the OP hasn't commented the second if as not working like the first one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;PROC&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;IMPORT&lt;/SPAN&gt; DATAFILE&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"/folders/myfolders/cars.xls"&lt;/SPAN&gt;
	DBMS&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;XLS
	OUT&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;WORK&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;cars_2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	GETNAMES&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;YES&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;RUN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; xx&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; cars_2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; n_cyl&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;NA &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; n_cyl&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;		&lt;SPAN class="token comment"&gt;*NOT WORKING;&lt;/SPAN&gt; 
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; luggage&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;NA &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; luggage&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;9&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;; /*this wouldn't work either??????*/&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;print&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;xx&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jan 2018 17:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427296#M68438</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-12T17:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to replace replace missing data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427300#M68439</link>
      <description>&lt;P&gt;Yet another reason not to use XLXS files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable(s) containing "NA" were created as text. So you would have to use a comparison such as&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; n_cyl&lt;SPAN class="token operator"&gt;="&lt;/SPAN&gt;NA" &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; n_cyl&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;; HOWEVER the variable will actually be text and not numeric. This line will also generate a note in the log that a numeric value was treated as text.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;If you want to create a numeric variable then you would a few choices. Easiest at this point is to create new variables by inputting the text:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;If n_cyl='NA' then Num_n_cyl=4;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;else Num_n_cyl = input(n_cyl, 4.); &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Other options would be to save the xlsx as a CSV file and use a data step to read it using a custom informat that would turn NA into the appropriate value for each variable (or if missing is the desired numeric result a standard SAS numeric informat). Note that Proc import for delimited files will create data step code that you can copy from the log and edit to change informats and such.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 17:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427300#M68439</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-12T17:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to replace replace missing data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427301#M68440</link>
      <description>&lt;P&gt;Pay attention, using NA unquoted treats it as a new numeric variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"NA" or 'NA' - is treated as a literal.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 17:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427301#M68440</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-01-12T17:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to replace replace missing data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427452#M68456</link>
      <description>&lt;P&gt;Take a look at the code you wrote.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if n_cyl=NA then n_cyl=4;		*NOT WORKING; 
if luggage=NA then luggage=9;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So in the first line you are comparing the character variable N_CYL to an unknown variable named NA.&amp;nbsp; So SAS will create a new variable which will be missing for every observation.&amp;nbsp; Then in the second line you are comparing the numeric variable LUGGAGE to this new empty variable.&amp;nbsp; So since NA is missing on every observation then&amp;nbsp;the second line will replace all of the missing values with nines.&lt;/P&gt;
&lt;PRE&gt;1    data test;
2      n_cyl='NA';
3      luggage=.;
4    run;

NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.20 seconds
      cpu time            0.01 seconds


5    data want ;
6     set test;
7    if n_cyl=NA then n_cyl=4;		*NOT WORKING;
8    if luggage=NA then luggage=9;
9    run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      7:24
NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      8:12
NOTE: Variable NA is uninitialized.&lt;/PRE&gt;
&lt;P&gt;The best way to fix this is to NOT put character strings like 'NA' into cells of your Excel file for numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really mean that the value is missing?&amp;nbsp; If so then just leave the cell empty in Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to convey that the value is missing, but for a different reason than a simple missing value? In SAS you would use a special missing value, like .A or .B. That is hard to do in Excel and get it to easily translate into SAS.&amp;nbsp; If you store your raw data in a text file then just using the single letter from the special missing will allow you to store those and normal numeric input will convert the letter into the special missing.&amp;nbsp; You should run the MISSING statement first to let SAS know which letter to recognize and which to reject as invalid numeric values.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 16:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427452#M68456</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-13T16:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to replace replace missing data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427456#M68457</link>
      <description>Thanks Tom&lt;BR /&gt;Problem solved ,now I can carry on analysis</description>
      <pubDate>Sat, 13 Jan 2018 18:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Unable-to-replace-replace-missing-data/m-p/427456#M68457</guid>
      <dc:creator>Sai_Sampath</dc:creator>
      <dc:date>2018-01-13T18:07:59Z</dc:date>
    </item>
  </channel>
</rss>

