<?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 How to extract string if it contains another variable ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498803#M132633</link>
    <description>&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS data set with that has two variables&lt;/P&gt;&lt;P&gt;1) a variable that contains the file number&lt;/P&gt;&lt;P&gt;2) a variable contains a text with a clinical diagnosis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The file number is found in its own variable but can also be found at the beginning of the diagnosis text.&lt;/P&gt;&lt;P&gt;I would like to extract only what is after the file number in the diagnosis variable. Sometimes, there is a space bar between the file number and the diagnosis description while sometimes, there no space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to tell SAS that when the content of file_number is found in the diagnosis variable, only keep what is after that number?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an exemple of what I have :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;file_number&lt;/TD&gt;&lt;TD&gt;diagnosis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;file:123456789The patient has…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;file:987654321 The patient has…&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I want :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;file_number&lt;/TD&gt;&lt;TD&gt;diagnosis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;The patient has…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;The patient has…&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 25 Sep 2018 18:33:41 GMT</pubDate>
    <dc:creator>dera</dc:creator>
    <dc:date>2018-09-25T18:33:41Z</dc:date>
    <item>
      <title>How to extract string if it contains another variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498803#M132633</link>
      <description>&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS data set with that has two variables&lt;/P&gt;&lt;P&gt;1) a variable that contains the file number&lt;/P&gt;&lt;P&gt;2) a variable contains a text with a clinical diagnosis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The file number is found in its own variable but can also be found at the beginning of the diagnosis text.&lt;/P&gt;&lt;P&gt;I would like to extract only what is after the file number in the diagnosis variable. Sometimes, there is a space bar between the file number and the diagnosis description while sometimes, there no space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to tell SAS that when the content of file_number is found in the diagnosis variable, only keep what is after that number?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an exemple of what I have :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;file_number&lt;/TD&gt;&lt;TD&gt;diagnosis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;file:123456789The patient has…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;file:987654321 The patient has…&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I want :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;file_number&lt;/TD&gt;&lt;TD&gt;diagnosis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;The patient has…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;The patient has…&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Sep 2018 18:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498803#M132633</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-09-25T18:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string if it contains another variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498819#M132635</link>
      <description>&lt;P&gt;Lots of people can help with that.&amp;nbsp; But the programming would change depending on whether FILE_NUMBER is numeric or character.&amp;nbsp; So let us know that.&amp;nbsp; Also, is FILE_NUMBER always present or could it contain a missing value?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 19:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498819#M132635</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-25T19:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string if it contains another variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498820#M132636</link>
      <description>&lt;P&gt;File number is a character and is always present for each observation. Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 19:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498820#M132636</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-09-25T19:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string if it contains another variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498823#M132637</link>
      <description>&lt;P&gt;OK, this should do it then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;diagnosis = substr(diagnosis, length(diagnosis) + index(diagnosis, strip(file_number)));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give it a try just to verify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better yet:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;diagnosis = substr(diagnosis, length(&lt;FONT color="#FF0000"&gt;file_number&lt;/FONT&gt;) + index(diagnosis, strip(file_number)));&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 19:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498823#M132637</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-25T19:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string if it contains another variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498825#M132638</link>
      <description>&lt;P&gt;Take a look at the TRANWRD function which will replace a word with specified value, in this case, a blank string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0pgemqcslm9uen1tvr5gcrusgrw.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1scxr4q5ix5cun10r10eyqn5oen" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0pgemqcslm9uen1tvr5gcrusgrw.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1scxr4q5ix5cun10r10eyqn5oen&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several examples at the bottom that illustrate how they can be used.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 19:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498825#M132638</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-25T19:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string if it contains another variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498827#M132639</link>
      <description>&lt;P&gt;Yes, here is one way of approaching this question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*** starting position of filenumber inside the diagnosis;

startFinD = FIND(diagnosis, filenumber); 

*** position of the first letter (or blank) of the new diagnosis;

startNewD = startFinD + 9;

*** new diagnosis variable;

diagnosis = STRIP[ SUBSTR(diagnosis, startNewD) ];

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 03:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498827#M132639</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2018-09-26T03:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string if it contains another variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498829#M132640</link>
      <description>&lt;P&gt;Thank you Astounding!&lt;BR /&gt;I used your idea with a small modification and it worked perfectly. Here is what I did :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;diagnosis = substr(diagnosis, length(&lt;FONT color="#FF0000"&gt;file_number&lt;/FONT&gt;) + index(diagnosis, strip(file_number)));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 16:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498829#M132640</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-09-26T16:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string if it contains another variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498834#M132642</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input file_number :$10.	diagnosis  &amp;amp; $100.;
cards;
123456789	file:123456789The patient has…
987654321	file:987654321 The patient has…
;

data want;
set have;
substr(diagnosis,1,14)=' ';
diagnosis=strip(diagnosis);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This assumes the pattern in diagnosis variable file:10 digit numbers is consistent&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 19:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-if-it-contains-another-variable/m-p/498834#M132642</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-25T19:36:04Z</dc:date>
    </item>
  </channel>
</rss>

