<?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: Extracting numbers from a mixed variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452662#M283960</link>
    <description>&lt;P&gt;Sorry for the typo...last record does not have the extra X. It should be 89x45 (x148)&lt;/P&gt;</description>
    <pubDate>Mon, 09 Apr 2018 21:08:29 GMT</pubDate>
    <dc:creator>sms1891</dc:creator>
    <dc:date>2018-04-09T21:08:29Z</dc:date>
    <item>
      <title>Extracting numbers from a mixed variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452660#M283958</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have a variable (Size_Cyst) recorded with height, length and width dimensions in a single variable. I want to extract them as 3 separate variables (height, length and width). The problem with the original variable is it is recorded as 261x 143 (x245)&amp;nbsp; to give you all an example. 261 corresponds to height, 143 for length and 245 for width.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All I want to do is to create 3 separate variables. The numbers before first x as height,&amp;nbsp; numbers after first x as length, i.e the middle set of numbers. And finally the numbers after second x as width, i.e in the parenthesis without x. Each of these numbers are not fixed, in the sense they may be 3 digit or 2 digit. It varies from ID to ID. However they range only from 2 digit to 3 digit ONLY. And also there are spacing issues between the numbers and X's, it is not captured consistently (e.g:&amp;nbsp; 261x 143 (x245)&amp;nbsp; 198 x 97 (x 160)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use compress I can get the numbers but I may lose the actual size. For 261x 143 (x245) i want it to be 261, 143 and 245 but not 26 1143 and 143...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help with the SAS code for this extraction would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the example of my data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Size_Cyst&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 261x 143 (x245)&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23x 14 (x27)&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23 x 14 (x 27)&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 243 x 14 (x234)&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 33 x 233 (x 67)&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 89x45x (x148)&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 21:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452660#M283958</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2018-04-09T21:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from a mixed variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452661#M283959</link>
      <description>&lt;P&gt;Use SCAN with the X delimiter since that seems consistent.&lt;/P&gt;
&lt;P&gt;Use COMPRESS to keep only digits&lt;/P&gt;
&lt;P&gt;Use INPUT to convert to a numeric variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last record seems to have an extra X, which may be problematic, but if you scan in a loop that should work still.&lt;/P&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/146852"&gt;@sms1891&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a variable (Size_Cyst) recorded with height, length and width dimensions in a single variable. I want to extract them as 3 separate variables (height, length and width). The problem with the original variable is it is recorded as 261x 143 (x245)&amp;nbsp; to give you all an example. 261 corresponds to height, 143 for length and 245 for width.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All I want to do is to create 3 separate variables. The numbers before first x as height,&amp;nbsp; numbers after first x as length, i.e the middle set of numbers. And finally the numbers after second x as width, i.e in the parenthesis without x. Each of these numbers are not fixed, in the sense they may be 3 digit or 2 digit. It varies from ID to ID. However they range only from 2 digit to 3 digit ONLY. And also there are spacing issues between the numbers and X's, it is not captured consistently (e.g:&amp;nbsp; 261x 143 (x245)&amp;nbsp; 198 x 97 (x 160)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I use compress I can get the numbers but I may lose the actual size. For 261x 143 (x245) i want it to be 261, 143 and 245 but not 26 1143 and 143...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help with the SAS code for this extraction would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the example of my data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Size_Cyst&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 261x 143 (x245)&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23x 14 (x27)&lt;/P&gt;
&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23 x 14 (x 27)&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 243 x 14 (x234)&lt;/P&gt;
&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 33 x 233 (x 67)&lt;/P&gt;
&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 89x45x (x148)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 21:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452661#M283959</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-09T21:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from a mixed variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452662#M283960</link>
      <description>&lt;P&gt;Sorry for the typo...last record does not have the extra X. It should be 89x45 (x148)&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 21:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452662#M283960</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2018-04-09T21:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from a mixed variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452663#M283961</link>
      <description>&lt;P&gt;As character variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;height = scan(size_cyst, 1, 'Xx( )');&lt;/P&gt;
&lt;P&gt;length&amp;nbsp;= scan(size_cyst, 2, 'Xx( )');&lt;/P&gt;
&lt;P&gt;width = scan(size_cyst, 3, 'Xx( )');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get these variables as numeric takes a little more work.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;height = &lt;FONT color="#ff0000"&gt;input(&lt;/FONT&gt;scan(size_cyst, 1, 'Xx( )')&lt;FONT color="#ff0000"&gt;, 3.)&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also notice that the space in the third parameter of SCAN is required.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 21:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452663#M283961</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-09T21:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from a mixed variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452668#M283962</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID     Size_Cyst &amp;amp; $20.;
datalines;
1      261x 143 (x245)
2      23x 14 (x27)
3      23 x 14 (x 27)
4      243 x 14 (x234)
5      33 x 233 (x 67)
6      89x45x (x148)
;

data want;
set have;
t=compress(translate(Size_Cyst,' ','x'),' ','kd');
height=scan(t,1);
length=scan(t,2);
width=scan(t,3);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You don;t need input to convert to numeric as sas will do auto conversion when you compute arithmetic&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 21:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452668#M283962</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-09T21:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from a mixed variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452814#M283963</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID     Size_Cyst &amp;amp; $20.;
datalines;
1      261x 143 (x245)
2      23x 14 (x27)
3      23 x 14 (x 27)
4      243 x 14 (x234)
5      33 x 233 (x 67)
6      89x45x (x148)
;

data want;
set have;
do i=1 to countw( Size_Cyst,,'kd');
  value=scan( Size_Cyst,i,,'kd'); output;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 13:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-numbers-from-a-mixed-variable/m-p/452814#M283963</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-04-10T13:30:29Z</dc:date>
    </item>
  </channel>
</rss>

