<?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: if then else if in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538266#M6908</link>
    <description>&lt;P&gt;The SUBSTR Function requires a character argument.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Feb 2019 14:08:58 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-02-25T14:08:58Z</dc:date>
    <item>
      <title>if then else if</title>
      <link>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538261#M6907</link>
      <description>&lt;P&gt;Using SAS 9.4&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble with an else/else if statement. The program will run but in the new column I am creating it does not populate any data. I have checked my POST_CD5 and made sure the data are numeric. Any thoughts on my code would be helpful. Thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.25Feb ;&lt;BR /&gt;set working.19Feb;&lt;BR /&gt;format county $char30.;&lt;BR /&gt;length COUNTY $100;&lt;BR /&gt;IF substr (POST_CD5, 1,5) in (00801) THEN COUNTY = 'Virgin Islands';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (27105, 27284) THEN COUNTY = 'Forsyth County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28012, 28052, 28098, 28120, 28164) THEN COUNTY = 'Gaston County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28025, 28027, 28081) THEN COUNTY = 'Cabarrus County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28036, 28078, 28105, 28134, 28202, 28205, 28207,&lt;BR /&gt;28211, 28213, 28214, 28215, 28216, 28217, 28226,&lt;BR /&gt;28227, 28262, 28269, 28270, 28277, 28278) THEN COUNTY = 'Mecklenburg County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28037) THEN COUNTY = 'Lincoln County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28079, 28110, 28173) THEN COUNTY = 'Union County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28086, 28090, 28150) THEN COUNTY = 'Cleveland County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28092) THEN COUNTY = 'Lincoln County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28115) THEN COUNTY = 'Iredell County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28127) THEN COUNTY = 'Stanly County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28139) THEN COUNTY = 'Rutherford County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28146) THEN COUNTY = 'Rowan County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28379) THEN COUNTY = 'Richmond County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28412) THEN COUNTY = 'New Hanover County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28601) THEN COUNTY = 'Catawba County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28604) THEN COUNTY = 'Watauga County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (28777) THEN COUNTY = 'Mitchell County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (29067) THEN COUNTY = 'Lincoln County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (29210) THEN COUNTY = 'Richland County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (29340) THEN COUNTY = 'Cherokee County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (29707, 29720) THEN COUNTY = 'Lancaster County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (29708, 29710, 29715, 29732, 29745) THEN COUNTY = 'York County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (29727, 29728) THEN COUNTY = 'Chesterfield County';&lt;BR /&gt;else if&lt;BR /&gt;substr (POST_CD5, 1,5) in (29909) THEN COUNTY = 'Beaufort County';&lt;BR /&gt;ELSE;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 14:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538261#M6907</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2019-02-25T14:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: if then else if</title>
      <link>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538266#M6908</link>
      <description>&lt;P&gt;The SUBSTR Function requires a character argument.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 14:08:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538266#M6908</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-25T14:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: if then else if</title>
      <link>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538267#M6909</link>
      <description>So you checked that POST_CD5 is numeric.  So far so good.  But SUBSTR works on character strings not numerous.  So your code forces SAS to name a numeric to character conversion.  If you read the log, you will see many such notes.&lt;BR /&gt;&lt;BR /&gt;If I recall, the latest version of the software contains a SUBSTRN function for numerous.  If so, that would be a simple solution.</description>
      <pubDate>Mon, 25 Feb 2019 14:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538267#M6909</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-25T14:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: if then else if</title>
      <link>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538269#M6911</link>
      <description>&lt;P&gt;Yes that worked as soon as I saw the first comment I realized what it was. Thanks for the help&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 14:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538269#M6911</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2019-02-25T14:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: if then else if</title>
      <link>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538273#M6912</link>
      <description>&lt;P&gt;I would advise you change your code slightly to make it more readable, but also more expandable/maintainable.&amp;nbsp; Your code is effectively stating that the first 5 characters of the string indicate location.&amp;nbsp; So what we can do in this instance is create a variable, call it location, which holds the first 5 characters - I will keep it as char, but you could use numeric;&lt;/P&gt;
&lt;PRE&gt;proc format;
  value $loc
    "00801"="Virgin Islands"
    "27105","27284"="Forsyth County"
    ...
;
run;

data feb25;
  set feb19;
  location=substr(post_cd5,1,5);
  format location $loc.;
run;&lt;/PRE&gt;
&lt;P&gt;You may even find there is already a dataset or format in sashelp with this information.&amp;nbsp; The above is far simpler and expandable than endless if statements.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 14:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/if-then-else-if/m-p/538273#M6912</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-25T14:31:10Z</dc:date>
    </item>
  </channel>
</rss>

