<?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 Numeric variables values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476359#M122589</link>
    <description>&lt;P&gt;'-' is a string. Numeric variables can never hold a string&lt;BR /&gt;Start by correcting this when you read the csv:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input _numval $;
if _numval = '-'
then numval = .;
else numval = input(_numval,best.);
drop _numval;
cards;
1
2
3
-
4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Jul 2018 06:00:30 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-07-09T06:00:30Z</dc:date>
    <item>
      <title>Replace Numeric variables values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476356#M122587</link>
      <description>&lt;P&gt;I am trying to infile&amp;nbsp;a csv file into SAS. However in the CSV, an hypen&amp;nbsp;is used to designate values as missing. Obviously, this causes problems because hyphens&amp;nbsp;cannot be read in as missing. So I believe, I need to replace all hyphens&amp;nbsp;in the numeric variables to periods. I am using SAS BASE 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are some of my attempts.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data fixed_total_genders;&lt;/P&gt;&lt;P&gt;set total_genders;&lt;/P&gt;&lt;P&gt;array change _numeric_;&lt;/P&gt;&lt;P&gt;if change eq '-' then call missing(of change);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data fixed_total_genders;&lt;/P&gt;&lt;P&gt;set total_genders;&lt;/P&gt;&lt;P&gt;array(*) _numeric_;&lt;/P&gt;&lt;P&gt;do i=1 to dim(a);&lt;/P&gt;&lt;P&gt;if a(i) = - then a(i) = .;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 05:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476356#M122587</guid>
      <dc:creator>Khooper</dc:creator>
      <dc:date>2018-07-09T05:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Numeric variables values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476359#M122589</link>
      <description>&lt;P&gt;'-' is a string. Numeric variables can never hold a string&lt;BR /&gt;Start by correcting this when you read the csv:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input _numval $;
if _numval = '-'
then numval = .;
else numval = input(_numval,best.);
drop _numval;
cards;
1
2
3
-
4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jul 2018 06:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476359#M122589</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-09T06:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Numeric variables values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476367#M122595</link>
      <description>&lt;P&gt;newvar=input(tranwrd(var,'-',''),best12.);&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 06:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476367#M122595</guid>
      <dc:creator>pau13rown</dc:creator>
      <dc:date>2018-07-09T06:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Numeric variables values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476373#M122596</link>
      <description>&lt;P&gt;Using the Input Statement ?? format modifier allows the value to be set to missing,&amp;nbsp;suppresses the warning message in the log and sets the _ERROR_ automatic variable to 0.&amp;nbsp; The same applies to the Input function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
input numval ??;
cards;
1
2
3
-
4
;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jul 2018 07:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476373#M122596</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2018-07-09T07:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Numeric variables values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476376#M122597</link>
      <description>&lt;P&gt;Which of the methods suggested above you use will depend on your need for checking the validity of the input.&lt;/P&gt;
&lt;P&gt;See this example code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input _numval :$10.;
if _numval = '-'
then numval1 = .;
else numval1 = input(_numval,best.);
numval2 = input(tranwrd(_numval,'-',''),best12.);
numval3 = input(_numval,?? best.);
cards;
1
2018-07-09
xxxxx
-
.
--
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now take a close look at the log of this data step and see which values are converted by the three methods without causing a NOTE and setting _ERROR_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 07:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476376#M122597</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-09T07:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Numeric variables values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476499#M122642</link>
      <description>&lt;P&gt;And my favorite for such things: a custom informat:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue nodash
'-'=.
other=[best12.]
;
run;

data work.example;
  input x nodash.;
datalines;
1
12345.666
-
abc
1.2E14
;
run;&lt;/PRE&gt;
&lt;P&gt;Since it is likely that I will process multiple files with the same layout and data conventions informats as either part of the read code or in permanent format catalogs in the current format search path make sense. I know that the - isn't an error but I want other erroneous data to throw errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 15:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-Numeric-variables-values/m-p/476499#M122642</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-09T15:49:22Z</dc:date>
    </item>
  </channel>
</rss>

