<?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: Creating variable conditional on string part in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161905#M3067</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I love regular expressions but in your case I would use a simple findw() function.&lt;/P&gt;&lt;P&gt;With a RegEx I would use the 'i' switch so the search pattern is not case sensitive and I would use the \b metacharacter to only find "delisted" if it's a word on it's own.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input x &amp;amp; $40.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if findw(x,'delisted','( ','i') then found1=1; else found1=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch('/\bdelisted\b/oi',x) then found2=1;else found2=0; &lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;ABC (delisted in 1/1/2010)&lt;/P&gt;&lt;P&gt;DEF&lt;/P&gt;&lt;P&gt;CompABC (public 2007)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Jan 2015 01:03:31 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2015-01-02T01:03:31Z</dc:date>
    <item>
      <title>Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161901#M3063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;suppose I have the following table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="80" style="border: 1px solid rgb(0, 0, 0); width: 251px; height: 82px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;company&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ABC (delisted in 1/1/2010)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;DEF&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to get the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="74" style="border: 1px solid rgb(0, 0, 0); width: 232px; height: 75px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;company&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;delist&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ABC (delisted in 1/1/2010)&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;yes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;DEF&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;no&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, if in the company's name the word "delisted" is present, I would like to have a new column that says "yes", and if the company wan't delisted, then "no" will appear&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Dec 2014 16:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161901#M3063</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2014-12-24T16:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161902#M3064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please read Docs on FIND(), FINDW(), INDEX, INDEXW(), COUNT() or you want something spicier, PRXMATCH().&lt;/P&gt;&lt;P&gt;If you use Proc SQL, you can also explore CONTAINS or LIKE clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Dec 2014 16:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161902#M3064</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-12-24T16:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161903#M3065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input x &amp;amp; $40.;&lt;/P&gt;&lt;P&gt;if prxmatch('/\(.*\)/',x) then found=1;else found=0;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;ABC (delisted in 1/1/2010)&lt;/P&gt;&lt;P&gt;DEF&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Dec 2014 08:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161903#M3065</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-12-25T08:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161904#M3066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Xia Keshan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the code, I did it and it worked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was just wandering, in your code the prxmatch is looking for parentheses, but if I do have for some company parentheses like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CompABC (public 2007)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then found will be 1 for this as well, so what I did is the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; prxmatch(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"/delisted /"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,company) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; found=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; found=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;I ran the code on a small sample and it seems to be working.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;Thank you and a happy new year! &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jan 2015 00:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161904#M3066</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-02T00:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161905#M3067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I love regular expressions but in your case I would use a simple findw() function.&lt;/P&gt;&lt;P&gt;With a RegEx I would use the 'i' switch so the search pattern is not case sensitive and I would use the \b metacharacter to only find "delisted" if it's a word on it's own.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input x &amp;amp; $40.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if findw(x,'delisted','( ','i') then found1=1; else found1=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch('/\bdelisted\b/oi',x) then found2=1;else found2=0; &lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;ABC (delisted in 1/1/2010)&lt;/P&gt;&lt;P&gt;DEF&lt;/P&gt;&lt;P&gt;CompABC (public 2007)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jan 2015 01:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161905#M3067</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-01-02T01:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161906#M3068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for your code, I ran it and obtained what I wanted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to ask you something else if I may:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a given company was delisted, how to create another column which will contain the date when the company was delisted?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Jan 2015 01:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161906#M3068</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-04T01:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161907#M3069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
&amp;nbsp; input x &amp;amp; $40.;
&amp;nbsp; if prxmatch('/\bdelisted\b/oi',x) then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found2=1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date=prxchange('s/.*(\d+\/\d+\/\d+).*/$1/oi',-1,x);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
else found2=0;
&amp;nbsp; cards;
ABC (delisted in 1/1/2010)
DEF
CompABC (public 2007)
;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Jan 2015 05:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161907#M3069</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-01-04T05:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161908#M3070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Xia Keshan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your code!!!&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; What I especially find interesting is that it will give me the date even if I have something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ABC (delisted in 1/1/2010 33.AA)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess that this is because the prxchange function, with the arguments you gave it, is searching for the first from the left string element that is in the date form as specified by the argument. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Jan 2015 18:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161908#M3070</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-04T18:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable conditional on string part</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161909#M3071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is a big advantage of Perl Regular Expression than the SAS function. I would prefer to use PRX firstly , then after that considering about SAS function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 06:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-variable-conditional-on-string-part/m-p/161909#M3071</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-01-05T06:00:06Z</dc:date>
    </item>
  </channel>
</rss>

