<?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 Converting height in ft.in (character) to inches (numeric) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780146#M248558</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some datasets&lt;/P&gt;
&lt;PRE&gt;1 ft 1 in
2ft2in
3 in
4in&lt;/PRE&gt;
&lt;P&gt;And I want to convert all of them to&amp;nbsp;numeric variables in inches.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;13
26
3
4&lt;/PRE&gt;
&lt;P&gt;Could anyone tell me how to do it, please? I'm confused because they have different units and spaces. Any hints would be helpful. Thank you in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 14 Nov 2021 17:37:16 GMT</pubDate>
    <dc:creator>aabbccwyt</dc:creator>
    <dc:date>2021-11-14T17:37:16Z</dc:date>
    <item>
      <title>Converting height in ft.in (character) to inches (numeric)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780146#M248558</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some datasets&lt;/P&gt;
&lt;PRE&gt;1 ft 1 in
2ft2in
3 in
4in&lt;/PRE&gt;
&lt;P&gt;And I want to convert all of them to&amp;nbsp;numeric variables in inches.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;13
26
3
4&lt;/PRE&gt;
&lt;P&gt;Could anyone tell me how to do it, please? I'm confused because they have different units and spaces. Any hints would be helpful. Thank you in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 17:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780146#M248558</guid>
      <dc:creator>aabbccwyt</dc:creator>
      <dc:date>2021-11-14T17:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Converting height in ft.in (character) to inches (numeric)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780147#M248559</link>
      <description>&lt;P&gt;Here is what I have for now&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Height = compress(Height);
	if findw(Height,'ft') &amp;gt; 0 then do;
	ft = input(scan(Height,1,"ft"),f1.);
	in = input(scan(Height,2,"in"),best.);
	Height = 12*ft + 1*in;
	else;
	Height = Height;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It gives errors but I'm just wondering if this is the right way to go or if there are easier ones.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 17:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780147#M248559</guid>
      <dc:creator>aabbccwyt</dc:creator>
      <dc:date>2021-11-14T17:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Converting height in ft.in (character) to inches (numeric)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780151#M248561</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data heights;
    input text $char60.;
    cards;
1 ft 1 in
2ft2in
3 in
4in
;
data want;
    set heights;
    text=compress(text);
    location_ft=find(text,'ft','i');
    location_in=find(text,'in','i');
    if location_in&amp;gt;0 then do;
    	inches=scan(substr(text,1,location_in-1),-1,,'dk');
  	    inches_numeric=input(inches,2.);
	end;
    if location_ft&amp;gt;0 then do;
    	feet=scan(substr(text,1,location_ft-1),-1,,'dk');
    	feet_numeric=input(feet,2.);
	end;
	height=sum(inches_numeric,12*feet_numeric);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Nov 2021 19:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780151#M248561</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-14T19:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting height in ft.in (character) to inches (numeric)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780171#M248571</link>
      <description>&lt;P&gt;You could use a regular expression to extract the numbers from the string:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set heights;
   
   length feet inch total 8;
   
   rx = prxparse('/((\d+)\s*ft)?\s*(\d+)\s*in/i');
   
   if prxmatch(rx, text) then do;
      feet = coalesce(input(prxposn(rx, 2, text), ?? best.), 0);
      inch = input(prxposn(rx, 3, text), ?? best.);
      
      total = sum(inch, feet * 12);
   end;
   else do;
      put 'Failed ' _n_;
   end;
   
   drop rx;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Nov 2021 05:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780171#M248571</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-11-15T05:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Converting height in ft.in (character) to inches (numeric)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780199#M248576</link>
      <description>&lt;P&gt;With data like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;                
  infile cards truncover; 
  input measure $10.;     
cards;                    
1 ft 1 in                 
2ft2in                    
3 in                      
4in                       
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would do it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                       
  set have;                                      
  measure=upcase(measure);                       
  if countw(measure,' ','A')=2 then              
    inches=input(scan(measure,1,' ','A'),4.)*12+ 
           input(scan(measure,2,' ','A'),4.);    
  else if index(measure,'FT') then               
    inches=input(scan(measure,1,' ','A'),4.)*12; 
  else                                           
    inches=input(scan(measure,1,' ','A'),4.);    
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put in the UPCASE function in case you have data like '12Ft' or so.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 09:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-height-in-ft-in-character-to-inches-numeric/m-p/780199#M248576</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-15T09:10:31Z</dc:date>
    </item>
  </channel>
</rss>

