<?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: How do I separate this variable into 2 variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865776#M341893</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;loc=find(shift,' to ', -(lengthn(shift)));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Mar 2023 17:04:15 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2023-03-22T17:04:15Z</dc:date>
    <item>
      <title>How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865736#M341877</link>
      <description>&lt;P&gt;Hi, I'm trying to separate this one variable into a 2 variables called pre and post, and i don't understand why i'm having difficulty in doing this using the scan function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1; 
infile datalines dsd dlm=",";
length shift $200;
	input shift $;
datalines;
stable to stable,
stable to unstable,
unstable to stable,
zero (empty) to +1 (ok),
+1 (ok) to +2 (good)
;
run;


data want; set have1;
pre=scan(shift, 1, " to ");
post=scan(shift, 2, " to ");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;When I use my code for the data step want, i get this, which is what i don't want:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hello_there_0-1679494745984.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81927i095CE5AC18CFE0B9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hello_there_0-1679494745984.png" alt="Hello_there_0-1679494745984.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 14:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865736#M341877</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-22T14:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865739#M341878</link>
      <description>&lt;P&gt;SCAN uses the letters in the third argument to split words. Your third argument contains the letter 't', and so on line one, the first "word" ends when a 't' is found, which means the first "word" is 's' (from the text string 'stable to stable');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; 
    set have1;
    where=find(shift,' to ');
    pre=substr(shift,1,where-1);
    post=substr(shift,where+4);
    drop where;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 14:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865739#M341878</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-22T14:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865741#M341880</link>
      <description>&lt;P&gt;Scan() separates over a single character. Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1; 
infile datalines dsd dlm=",";
length shift $200;
	input shift $;
datalines;
stable to stable,
stable to unstable,
unstable to stable,
zero (empty) to +1 (ok),
+1 (ok) to +2 (good)
;
run;


data want; 
set have1;
shift1=tranwrd(shift, " to ", "#");
pre=scan(shift1, 1, "#");
post=scan(shift1, 2, "#");
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 14:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865741#M341880</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-03-22T14:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865742#M341881</link>
      <description>This worked perfectly. Thanks, PaigeMiller!</description>
      <pubDate>Wed, 22 Mar 2023 14:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865742#M341881</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-22T14:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865744#M341883</link>
      <description>Brilliant! Thanks, Bart, that works also!</description>
      <pubDate>Wed, 22 Mar 2023 14:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865744#M341883</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-22T14:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865773#M341890</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; , do you know i would account for if there is more than 1 " to ", and i just want what's after the last one?&lt;/P&gt;
&lt;P&gt;The last value has 2 " to ".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1; 
infile datalines dsd dlm=",";
length shift $200;
	input shift $;
datalines;
stable to stable,
stable to unstable,
unstable to stable,
zero (empty) to +1 (ok),
+1 (ok) to +2 (good)
zero (good to good) to +3 (great)
;
run;


data want; 
    set have1;
    loc=find(shift,' to ');
    pre=substr(shift,1,loc-1);
    post=substr(shift,loc+4);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2023 16:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865773#M341890</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-22T16:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865775#M341892</link>
      <description>Actually, never mind, there's another variable in my data set that will help me so i don't have to parse this text anymore than i have to. Ignore my previous reply.&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Mar 2023 17:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865775#M341892</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-22T17:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865776#M341893</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;loc=find(shift,' to ', -(lengthn(shift)));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2023 17:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865776#M341893</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-03-22T17:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I separate this variable into 2 variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865777#M341894</link>
      <description>Thanks, Bart!</description>
      <pubDate>Wed, 22 Mar 2023 17:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-separate-this-variable-into-2-variables/m-p/865777#M341894</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-22T17:23:06Z</dc:date>
    </item>
  </channel>
</rss>

