<?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 Simplify IF THEN statements in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587390#M14682</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id$ match1$ match2$ match3$;
cards;
1 1 1 1
2 1 0 1
3 1 1 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and want to create the variable SCORE. I wrote:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
 if match1="1" and match2="1" and match3="1" then score="1";
 if match1="0" and match2="1" and match3="1" then score="2";
 if match1="1" and match2="0" and match3="1" then score="3";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In my code for the actual data set, SCORE increases by 1 in each subsequent IF THEN statement. Is there a way to simplify this? I was looking for threads on arrays but am still a little confused how to apply that here.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Sep 2019 00:49:28 GMT</pubDate>
    <dc:creator>bkq32</dc:creator>
    <dc:date>2019-09-10T00:49:28Z</dc:date>
    <item>
      <title>Simplify IF THEN statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587390#M14682</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id$ match1$ match2$ match3$;
cards;
1 1 1 1
2 1 0 1
3 1 1 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and want to create the variable SCORE. I wrote:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
 if match1="1" and match2="1" and match3="1" then score="1";
 if match1="0" and match2="1" and match3="1" then score="2";
 if match1="1" and match2="0" and match3="1" then score="3";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In my code for the actual data set, SCORE increases by 1 in each subsequent IF THEN statement. Is there a way to simplify this? I was looking for threads on arrays but am still a little confused how to apply that here.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 00:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587390#M14682</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2019-09-10T00:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify IF THEN statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587407#M14684</link>
      <description>&lt;P&gt;Technically, you are creating SCORE as a character variable.&amp;nbsp; So it's not really increasing by 1 each time, it's just a different character.&amp;nbsp; If you were to make SCORE a numeric variable instead, by removing the quotes around its assigned value, there might be other possibilities.&amp;nbsp; (Important note:&amp;nbsp; are match1 through match3 really character variables as well?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't necessarily simpler ... it's in the mind of the beholder:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
  if match3="1" then do;
    if match1="1" and match2="1" then score="1";
    if match1="0" and match2="1" then score="2";
    if match1="1" and match2="0" then score="3";
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Sep 2019 02:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587407#M14684</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-09-10T02:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify IF THEN statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587424#M14685</link>
      <description>&lt;P&gt;Is match3 = "1" true for all obs in your real data? If not, score will be missing for those obs. If yes: you can remove it from the if-statements.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 05:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587424#M14685</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-09-10T05:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify IF THEN statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587433#M14686</link>
      <description>&lt;P&gt;All the match variables are boolean, so I guess I don't need to make them character variables. I had sent Company A a file with demographic information, and they gave back a data set with these match variables which indicate that Company A also had a record in their database for a particular person (ID) that matched on a specific demographic (e.g. If match1 = 1, then the last name matched; If match2 = 1, then first name matched; If match3 = 1, then social security number matched, etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I now have to create a match score (variable SCORE) for each record that indicates how likely the record in my data set represents the same person in Company A's data set. I arbitrarily determined that a score of 1 indicates the highest likelihood that it's a true match when all demographic variables matched (=1). I'm then identifying the next slightly less ideal permutation (e.g. last name did not match) and giving it a score of 2, and so on, so all match variables will at some point take on 0s and 1s.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not opposed to writing out all the IF THEN statements, but was just wondering if there might be a more efficient way to do this.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 06:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587433#M14686</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2019-09-10T06:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify IF THEN statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587447#M14687</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288620"&gt;@bkq32&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think ideally there would be a formula to &lt;EM&gt;compute&lt;/EM&gt; SCORE from the MATCH&lt;EM&gt;x&lt;/EM&gt; variables (in which case all these variables should be numeric). For example, a reasonable SCORE might be a linear combination of MATCH1, MATCH2, ..., i.e.,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;SCORE=w1*MATCH1+w2*MATCH2+...&lt;/FONT&gt; where w1, w2, ...&amp;gt;0 are weights so that important matches like "last name" contribute more to the score than, say, "house number supplement." With a suitable formula this would mean: "the higher the score, the better the match" (contrary to your example scores). In particular, the perfect match (MATCH1=MATCH2=...MATCH&lt;EM&gt;n&lt;/EM&gt;=1) would automatically have the highest possible score.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's too difficult to develop such a formula and the scores are simply ("arbitrarily") assigned using a lookup table, you could store this table either&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;in a SAS dataset and then perform the assignment using a common lookup technique, e.g., by means of a hash object in a DATA step, which could look like this:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc=h.find(key:cats(of match:));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;or in a numeric informat, say, &lt;FONT face="courier new,courier"&gt;mscore&lt;/FONT&gt;&amp;nbsp;and then use the INPUT function to assign the score, e.g.:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;score=input(cats(of match:),mscore.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 10 Sep 2019 08:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587447#M14687</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-10T08:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify IF THEN statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587476#M14692</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id$ match1$ match2$ match3$;
cards;
1 1 1 1
2 1 0 1
3 1 1 1
;
run;
data want;
 set have;
 temp=cats(of match:);
 if temp='111' then score=1;
  else if temp='101' then score=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Sep 2019 11:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587476#M14692</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-09-10T11:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify IF THEN statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587535#M14704</link>
      <description>&lt;P&gt;Here's a simplistic, but perfectly valid way to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your MATCH variables have to be defined in order (match1=most important, match3 = least important).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SCORE will be numeric, with a &lt;STRONG&gt;higher&lt;/STRONG&gt; score being a better match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a single statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;score = input(cats(of match1-match3), binary3.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 14:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587535#M14704</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-09-10T14:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify IF THEN statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587601#M14714</link>
      <description>&lt;P&gt;Thanks everyone! These were really helpful.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 17:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simplify-IF-THEN-statements/m-p/587601#M14714</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2019-09-10T17:12:48Z</dc:date>
    </item>
  </channel>
</rss>

