<?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 find a word in a text variable and fill another variable if condition is met? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452175#M283873</link>
    <description>&lt;P&gt;Hi, I have a large dataset in which i am trying to fill blanks in a particular column based on certain criteria.&lt;BR /&gt;&lt;BR /&gt;My dataset looks like below.&lt;BR /&gt;Customer_Name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Degree Country&lt;BR /&gt;Steve&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USA&lt;BR /&gt;Dan&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CAN&lt;BR /&gt;Edward&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M.Tech USA&lt;BR /&gt;Emily MS -1st&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USA&lt;BR /&gt;John MBA - 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USA&lt;BR /&gt;&lt;BR /&gt;If Degree variable has blanks, Customer_Name will have a reference to the degree in it.&lt;BR /&gt;So, i want to build a logic that If Degree is blank then search Customer_Name for 'MS' and create a new variable "Degree_mod" and fill "MS" in it. In the above table, Emily and John should have entries in the new variable. Somehow i am not able build it.&lt;BR /&gt;data work.Daily_dump;&lt;BR /&gt;set work.Daily_Dump;&lt;BR /&gt;Format Degree_Mod $15.;&lt;BR /&gt;if Degree =' ' then do;&lt;BR /&gt;if FINDW(Customer_Name, 'MS')&amp;gt;0 then do; Degree_Mod1="MS";&lt;BR /&gt;end;&lt;BR /&gt;I am not sure if my SAS code is correct here. Can you please help?&lt;/P&gt;</description>
    <pubDate>Sat, 07 Apr 2018 10:06:32 GMT</pubDate>
    <dc:creator>saiksrini</dc:creator>
    <dc:date>2018-04-07T10:06:32Z</dc:date>
    <item>
      <title>How to find a word in a text variable and fill another variable if condition is met?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452175#M283873</link>
      <description>&lt;P&gt;Hi, I have a large dataset in which i am trying to fill blanks in a particular column based on certain criteria.&lt;BR /&gt;&lt;BR /&gt;My dataset looks like below.&lt;BR /&gt;Customer_Name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Degree Country&lt;BR /&gt;Steve&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USA&lt;BR /&gt;Dan&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CAN&lt;BR /&gt;Edward&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M.Tech USA&lt;BR /&gt;Emily MS -1st&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USA&lt;BR /&gt;John MBA - 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USA&lt;BR /&gt;&lt;BR /&gt;If Degree variable has blanks, Customer_Name will have a reference to the degree in it.&lt;BR /&gt;So, i want to build a logic that If Degree is blank then search Customer_Name for 'MS' and create a new variable "Degree_mod" and fill "MS" in it. In the above table, Emily and John should have entries in the new variable. Somehow i am not able build it.&lt;BR /&gt;data work.Daily_dump;&lt;BR /&gt;set work.Daily_Dump;&lt;BR /&gt;Format Degree_Mod $15.;&lt;BR /&gt;if Degree =' ' then do;&lt;BR /&gt;if FINDW(Customer_Name, 'MS')&amp;gt;0 then do; Degree_Mod1="MS";&lt;BR /&gt;end;&lt;BR /&gt;I am not sure if my SAS code is correct here. Can you please help?&lt;/P&gt;</description>
      <pubDate>Sat, 07 Apr 2018 10:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452175#M283873</guid>
      <dc:creator>saiksrini</dc:creator>
      <dc:date>2018-04-07T10:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a word in a text variable and fill another variable if condition is met?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452196#M283874</link>
      <description>&lt;P&gt;I would try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if degree = ' ' then degree_mod1 = scan(name, -2, '- ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be sure to include both characters (dash and blank) as delimiters for the SCAN function.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Apr 2018 13:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452196#M283874</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-07T13:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a word in a text variable and fill another variable if condition is met?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452217#M283875</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109376"&gt;@saiksrini&lt;/a&gt;, you wrote:&amp;nbsp; &amp;nbsp;"&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;Emily and John should have entries in the new variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;"&lt;/P&gt;
&lt;P&gt;In your code you check for the value&amp;nbsp; "MS" but there is no "MS" in John's line but "MBA".&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;proposed using SCAN() function instead checking for special value which seems more reasonable&lt;/P&gt;
&lt;P&gt;You need to verify that DEGREE_MOD is always separated by space and/or hyphen (" -") and nothing else.&lt;/P&gt;
&lt;P&gt;Can a name include a hyphen in it ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Apr 2018 18:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452217#M283875</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-04-07T18:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a word in a text variable and fill another variable if condition is met?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452229#M283876</link>
      <description>&lt;P&gt;You can use some SAS function to achieve this, but first you need to know how is your data . FIND(), INDEX(), along with SCAN(), SUBSTR() etc.. can be used.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also perl expressions can be used like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Add all the degrees here */
%LET Degrees=/ MS | MBA | M.Tech | MA /;
data want;
set have;
if prxmatch("&amp;amp;Degrees",Customer_Name) then
	Degree_mod=SCAN(substr(Customer_Name,prxmatch("&amp;amp;Degrees",Customer_Name)),1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Apr 2018 19:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-word-in-a-text-variable-and-fill-another-variable/m-p/452229#M283876</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-07T19:52:49Z</dc:date>
    </item>
  </channel>
</rss>

