<?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: Invalid character data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Invalid-character-data/m-p/723260#M224409</link>
    <description>&lt;LI-CODE lang="sas"&gt;If MotherHeight=" " THEN Ht_Inches=.;&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 03 Mar 2021 20:05:07 GMT</pubDate>
    <dc:creator>WarrenKuhfeld</dc:creator>
    <dc:date>2021-03-03T20:05:07Z</dc:date>
    <item>
      <title>Invalid character data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-character-data/m-p/723259#M224408</link>
      <description>&lt;P&gt;I am trying to create a new numeric variable called "Ht_Inches" which is coming from the variable "MotherHeight"&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Convert MotherHeight to Inches*/
If MotherHeight=" " THEN Ht_Inches=" ";
ELSE Ht_Inches= (INPUT(substr(MotherHeight,2,1),5.)*12)+ 
(INPUT(substr(MotherHeight,4,2),5.));
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is a screenshot of what the MotherHeight data looks like:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abrice520_2-1614801743587.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55409i1707F1C0DFA9DEA7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="abrice520_2-1614801743587.png" alt="abrice520_2-1614801743587.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is what the log says&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abrice520_1-1614801661505.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55408i2A18CA2F7421B734/image-size/medium?v=v2&amp;amp;px=400" role="button" title="abrice520_1-1614801661505.png" alt="abrice520_1-1614801661505.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 20:03:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-character-data/m-p/723259#M224408</guid>
      <dc:creator>abrice520</dc:creator>
      <dc:date>2021-03-03T20:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid character data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-character-data/m-p/723260#M224409</link>
      <description>&lt;LI-CODE lang="sas"&gt;If MotherHeight=" " THEN Ht_Inches=.;&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 03 Mar 2021 20:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-character-data/m-p/723260#M224409</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2021-03-03T20:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid character data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-character-data/m-p/723261#M224410</link>
      <description>&lt;P&gt;What's line 77 in your code, from the log? Please post the actual log as text, not as an image. Note that the data in the log is your data so make sure to mask any confidential information before posting which is much easier if it's text rather than an image. &lt;BR /&gt;&lt;BR /&gt;For your first IF statement, the ht_inches is supposed to be numeric? In that case, it should be a period or call missing not a blank space.&lt;BR /&gt;&lt;BR /&gt;If MotherHeight=" " THEN Ht_Inches=" ";&lt;BR /&gt;&lt;BR /&gt;Should be:&lt;BR /&gt;&lt;BR /&gt;if missing(motherHeight) then call missing(ht_inches);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Overall, this would be how I would do it, using SCAN instead of SUBSTR() but same idea overall:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note that your screenshot shows a ? which is not the same as missing&lt;/STRONG&gt;, so you would need to explicitly also handle that and a blank condition if that was in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If MotherHeight in ("?", "") THEN call missing(ht_inches);

ELSE Ht_Inches= input(scan(motherHeight, 1, ":"), 8.)*12 + input(scan(motherHeight, 2, ":"), 8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344351"&gt;@abrice520&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create a new numeric variable called "Ht_Inches" which is coming from the variable "MotherHeight"&lt;/P&gt;
&lt;P&gt;Here is my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Convert MotherHeight to Inches*/
If MotherHeight=" " THEN Ht_Inches=" ";
ELSE Ht_Inches= (INPUT(substr(MotherHeight,2,1),5.)*12)+ 
(INPUT(substr(MotherHeight,4,2),5.));
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is a screenshot of what the MotherHeight data looks like:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abrice520_2-1614801743587.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55409i1707F1C0DFA9DEA7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="abrice520_2-1614801743587.png" alt="abrice520_2-1614801743587.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here is what the log says&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abrice520_1-1614801661505.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55408i2A18CA2F7421B734/image-size/medium?v=v2&amp;amp;px=400" role="button" title="abrice520_1-1614801661505.png" alt="abrice520_1-1614801661505.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 20:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-character-data/m-p/723261#M224410</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-03T20:09:55Z</dc:date>
    </item>
  </channel>
</rss>

