<?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: replacing  char values with zero in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746284#M234096</link>
    <description>&lt;P&gt;To answer your specific question, even though I think this is not a good thing to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
     set have;
      if height='I don''t know how tall I am' then height='0';
      if weight='I don''t know how tall I am' then weight='0';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To do the calculation of means, you would have to convert these to numeric variables as stated by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;, but it really doesn't make sense to set these to zero, when you should be setting these to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it really say tall when weight is missing?&lt;/P&gt;</description>
    <pubDate>Mon, 07 Jun 2021 15:50:20 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-06-07T15:50:20Z</dc:date>
    <item>
      <title>replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746269#M234086</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need help in replacing &amp;nbsp;the value '&lt;STRONG&gt;I don't know how tall I am&lt;/STRONG&gt;' from &lt;STRONG&gt;height&lt;/STRONG&gt; column as well as&amp;nbsp;'&lt;STRONG&gt;I don't know how much I weigh&lt;/STRONG&gt;' from the weight column with the &lt;STRONG&gt;0&lt;/STRONG&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data Have&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;policy_no&amp;nbsp; &amp;nbsp; &amp;nbsp;height&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weight&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I don't know how tall I am &amp;nbsp;&amp;nbsp; 60&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;I don't know how tall I am&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;Data Want&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;policy_no&amp;nbsp; &amp;nbsp; &amp;nbsp;height&amp;nbsp; &amp;nbsp; &amp;nbsp;Weight&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 60&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;&lt;LI-CODE lang="sas"&gt;&lt;/LI-CODE&gt;&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 15:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746269#M234086</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2021-06-07T15:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746272#M234088</link>
      <description>&lt;P&gt;In your data set, are the variables HEIGHT and WEIGHT character or numeric? Please run PROC CONTENTS on this data set and show us. Also, if either of these variables have had a format applied, please identify which formats are used.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 15:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746272#M234088</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-07T15:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746273#M234089</link>
      <description>&lt;P&gt;Are you intending to do any analysis or summaries with the "height" and "weight" as actual numeric values?&lt;/P&gt;
&lt;P&gt;If so then you need create new variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps something like:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   numheight= input(height,?? 5.);
   if missing(numheight) then numheight=0;
   numweight= input(weight,?? 5.);
   if missing(numweight) then numweight=0;

run;&lt;/PRE&gt;
&lt;P&gt;INPUT is the way to create numeric values from text. The ?? suppresses the invalid data messages you would normally see when attempting to read "I don't know my height" into a numeric value. The IF assumes the reason for missing is something like your text entries and sets 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or change how you read the data into SAS to address such things earlier.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 15:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746273#M234089</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-07T15:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746279#M234092</link>
      <description>Hi, kindly see below proc contents below&lt;BR /&gt;&lt;BR /&gt;  Alphabetic List of Variables and Attributes                            &lt;BR /&gt;                                                                                                   &lt;BR /&gt;       #    Variable               Type    Len    Format    Informat    Label                      &lt;BR /&gt;                                                                                                   &lt;BR /&gt;       1    ExternalReferenceId    Char    255    $255.     $255.       ExternalReferenceId        &lt;BR /&gt;       2    Height                 Char    255    $255.                                            &lt;BR /&gt;       3    Weight                 Char    255    $255.</description>
      <pubDate>Mon, 07 Jun 2021 15:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746279#M234092</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2021-06-07T15:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746281#M234093</link>
      <description>&lt;P&gt;Hi, yes im intending to replace them with mean value for analysis&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 15:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746281#M234093</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2021-06-07T15:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746283#M234095</link>
      <description>&lt;P&gt;Then set them as MISSING, not a valid value like zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make new numeric variables to store the actual numbers.&lt;/P&gt;
&lt;PRE&gt;Alphabetic List of Variables and Attributes

# Variable Type Len Format Informat Label

1 ExternalReferenceId Char 255 $255. $255. ExternalReferenceId
2 Height Char 255 $255.
3 Weight Char 255 $255.&lt;/PRE&gt;
&lt;P&gt;Why are those fields length $255?&amp;nbsp; The longest string that the normal SAS informat can read is 32 characters.&lt;/P&gt;
&lt;P&gt;Here is a step that will create numeric variables HT and WT from your existing strings.&amp;nbsp; Anything that is not a valid number is converted to missing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  ht = input(left(height),32.);
  wt = input(left(weight),32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to suppress the warnings about invalid data you can use the ?? prefix on the informat.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 15:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746283#M234095</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-07T15:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746284#M234096</link>
      <description>&lt;P&gt;To answer your specific question, even though I think this is not a good thing to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
     set have;
      if height='I don''t know how tall I am' then height='0';
      if weight='I don''t know how tall I am' then weight='0';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To do the calculation of means, you would have to convert these to numeric variables as stated by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;, but it really doesn't make sense to set these to zero, when you should be setting these to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it really say tall when weight is missing?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 15:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746284#M234096</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-07T15:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746314#M234105</link>
      <description>&lt;P&gt;It's important to understand how SAS handles missing values, not understanding could lead to results you are not expecting:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A title="Understanding How SAS Handles Missing Values" href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/basess/p0i1iathn4xb1un1j4kg927qrblj.htm" target="_self"&gt;See Understanding How SAS Handles Missing Values&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a simple example that helps explain it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_ ;
	/* Notice how the mean of 0,1,2,3 = 1.5 that's because SAS calculates the mean as (0+1+2+3)/4 = 6/4 = 1.5 */
	avg=mean(0,1,2,3) ;
	put "Mean of 0,1,2,3 = " avg ;
	/* Notice how the mean of .,1,2,3 = 2 that's because SAS calculates the mean as (1+2+3)/3 = 6/3 = 2 */
	/* Basically SAS doesn't include missing values when using functions */
	avg=mean(.,1,2,3) ;
	put "Mean of .,1,2,3 = " avg ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 16:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746314#M234105</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-06-07T16:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746448#M234163</link>
      <description>thanks a lot</description>
      <pubDate>Tue, 08 Jun 2021 13:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/746448#M234163</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2021-06-08T13:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: replacing  char values with zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/754880#M238148</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input policy_no height $&amp;amp;100. weight $&amp;amp;100.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 I don't know how tall I am 60&lt;BR /&gt;2 1.5 I don't know how tall I am&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;data have2;&lt;BR /&gt;set have;&lt;BR /&gt;if anyalpha(height) then height='0';&lt;BR /&gt;if anyalpha(weight) then weight='0';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jul 2021 18:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacing-char-values-with-zero/m-p/754880#M238148</guid>
      <dc:creator>Brijesh4sas</dc:creator>
      <dc:date>2021-07-18T18:12:54Z</dc:date>
    </item>
  </channel>
</rss>

