<?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 DELETE SYNTAX in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907177#M358137</link>
    <description>&lt;P&gt;That's an example where using formats is beneficial.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78622"&gt;@ghosh&lt;/a&gt;&amp;nbsp;is basically proposing the same but using a table as source for the format instead of an explicit definition. I felt for your use case and assumed level of SAS expertise below syntax is likely easier to absorb.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value GeoId2County
    38001="Adams County"
    38003="Barnes County"
    38005="Benson County"
    38007="Billings County"
    38009="Bottineau County"
    38011="Bowman County"
    38013="Burke County"
    38015="Burleigh County"
    38017="Cass County"
    38019="Cavalier County"
    38021="Dickey County"
    38023="Divide County"
    38025="Dunn County"
    38027="Eddy County"
    38029="Emmons County"
    38031="Foster County"
    38033="Golden Valley County"
    38035="Grand Forks County"
    38037="Grant County"
    38039="Griggs County"
    38041="Hettinger County"
    38043="Kidder County"
    38045="LaMoure County"
    38047="Logan County"
    38049="McHenry County"
    38051="McIntosh County"
    38053="McKenzie County"
    38055="McLean County"
    38057="Mercer County"
    38059="Morton County"
    38061="Mountrail County"
    38063="Nelson County"
    38065="Oliver County"
    38067="Pembina County"
    38069="Pierce County"
    38071="Ramsey County"
    38073="Ransom County"
    38075="Renville County"
    38077="Richland County"
    38079="Rolette County"
    38081="Sargent County"
    38083="Sheridan County"
    38085="Sioux County"
    38087="Slope County"
    38089="Stark County"
    38091="Steele County"
    38093="Stutsman County"
    38095="Towner County"
    38097="Traill County"
    38099="Walsh County"
    38101="Ward County"
    38103="Wells County"
    38105="Williams County"
    other=" "
    ;
run;

data want;
  set have;
  if put(geoid,GeoId2County.) = " " then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Dec 2023 03:38:02 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-12-10T03:38:02Z</dc:date>
    <item>
      <title>IF THEN ELSE DELETE SYNTAX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907165#M358132</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to filter a huge dataset to locations of interest and here is the syntax I developed. I am not sure why SAS only is filtering my last line and not the whole locations I selected in my IF statements. Any thoughts on this is much appreciated:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data XXX;&lt;BR /&gt;set YYY;&lt;BR /&gt;IF GEOID=38001 THEN LOCATION="Adams County";&lt;BR /&gt;IF GEOID=38003 THEN LOCATION="Barnes County";&lt;BR /&gt;IF GEOID=38005 THEN LOCATION="Benson County";&lt;BR /&gt;IF GEOID=38007 THEN LOCATION="Billings County";&lt;BR /&gt;IF GEOID=38009 THEN LOCATION="Bottineau County";&lt;BR /&gt;IF GEOID=38011 THEN LOCATION="Bowman County";&lt;BR /&gt;IF GEOID=38013 THEN LOCATION="Burke County";&lt;BR /&gt;IF GEOID=38015 THEN LOCATION="Burleigh County";&lt;BR /&gt;IF GEOID=38017 THEN LOCATION="Cass County";&lt;BR /&gt;IF GEOID=38019 THEN LOCATION="Cavalier County";&lt;BR /&gt;IF GEOID=38021 THEN LOCATION="Dickey County";&lt;BR /&gt;IF GEOID=38023 THEN LOCATION="Divide County";&lt;BR /&gt;IF GEOID=38025 THEN LOCATION="Dunn County";&lt;BR /&gt;IF GEOID=38027 THEN LOCATION="Eddy County";&lt;BR /&gt;IF GEOID=38029 THEN LOCATION="Emmons County";&lt;BR /&gt;IF GEOID=38031 THEN LOCATION="Foster County";&lt;BR /&gt;IF GEOID=38033 THEN LOCATION="Golden Valley County";&lt;BR /&gt;IF GEOID=38035 THEN LOCATION="Grand Forks County";&lt;BR /&gt;IF GEOID=38037 THEN LOCATION="Grant County";&lt;BR /&gt;IF GEOID=38039 THEN LOCATION="Griggs County";&lt;BR /&gt;IF GEOID=38041 THEN LOCATION="Hettinger County";&lt;BR /&gt;IF GEOID=38043 THEN LOCATION="Kidder County";&lt;BR /&gt;IF GEOID=38045 THEN LOCATION="LaMoure County";&lt;BR /&gt;IF GEOID=38047 THEN LOCATION="Logan County";&lt;BR /&gt;IF GEOID=38049 THEN LOCATION="McHenry County";&lt;BR /&gt;IF GEOID=38051 THEN LOCATION="McIntosh County";&lt;BR /&gt;IF GEOID=38053 THEN LOCATION="McKenzie County";&lt;BR /&gt;IF GEOID=38055 THEN LOCATION="McLean County";&lt;BR /&gt;IF GEOID=38057 THEN LOCATION="Mercer County";&lt;BR /&gt;IF GEOID=38059 THEN LOCATION="Morton County";&lt;BR /&gt;IF GEOID=38061 THEN LOCATION="Mountrail County";&lt;BR /&gt;IF GEOID=38063 THEN LOCATION="Nelson County";&lt;BR /&gt;IF GEOID=38065 THEN LOCATION="Oliver County";&lt;BR /&gt;IF GEOID=38067 THEN LOCATION="Pembina County";&lt;BR /&gt;IF GEOID=38069 THEN LOCATION="Pierce County";&lt;BR /&gt;IF GEOID=38071 THEN LOCATION="Ramsey County";&lt;BR /&gt;IF GEOID=38073 THEN LOCATION="Ransom County";&lt;BR /&gt;IF GEOID=38075 THEN LOCATION="Renville County";&lt;BR /&gt;IF GEOID=38077 THEN LOCATION="Richland County";&lt;BR /&gt;IF GEOID=38079 THEN LOCATION="Rolette County";&lt;BR /&gt;IF GEOID=38081 THEN LOCATION="Sargent County";&lt;BR /&gt;IF GEOID=38083 THEN LOCATION="Sheridan County";&lt;BR /&gt;IF GEOID=38085 THEN LOCATION="Sioux County";&lt;BR /&gt;IF GEOID=38087 THEN LOCATION="Slope County";&lt;BR /&gt;IF GEOID=38089 THEN LOCATION="Stark County";&lt;BR /&gt;IF GEOID=38091 THEN LOCATION="Steele County";&lt;BR /&gt;IF GEOID=38093 THEN LOCATION="Stutsman County";&lt;BR /&gt;IF GEOID=38095 THEN LOCATION="Towner County";&lt;BR /&gt;IF GEOID=38097 THEN LOCATION="Traill County";&lt;BR /&gt;IF GEOID=38099 THEN LOCATION="Walsh County";&lt;BR /&gt;IF GEOID=38101 THEN LOCATION="Ward County";&lt;BR /&gt;IF GEOID=38103 THEN LOCATION="Wells County"; &lt;BR /&gt;IF GEOID=38105 THEN LOCATION="Williams County";&lt;BR /&gt;else delete;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2023 15:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907165#M358132</guid>
      <dc:creator>raheleh22</dc:creator>
      <dc:date>2023-12-09T15:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN ELSE DELETE SYNTAX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907166#M358133</link>
      <description>&lt;P&gt;That is the expected behavior.&amp;nbsp; Technically, ELSE refers to the most recent IF/THEN condition only and tests:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Was the most recent IF/THEN condition evaluated?&amp;nbsp; and&lt;/LI&gt;
&lt;LI&gt;Was it found to be false?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;To connect all of the conditions in the way you would like, you would need to repeat the word ELSE, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF GEOID=38097 THEN LOCATION="Traill County";
ELSE IF GEOID=38099 THEN LOCATION="Walsh County";
ELSE IF GEOID=38101 THEN LOCATION="Ward County";
ELSE IF GEOID=38103 THEN LOCATION="Wells County";
ELSE IF GEOID=38105 THEN LOCATION="Williams County";
else delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For readability, I would suggest switching to SELECT/WHEN instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select (GEOID);
   when (38097)  location = 'Traill County';
   when (38099)  location = 'Walsh County';
   when (38101)  location = 'Ward County';
   when (38103)  location = 'Wells County';
   when (38105)  location = 'Williams County';
   otherwise delete;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course you have to add to the program to specify your entire list, not just 5 of the counties.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2023 16:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907166#M358133</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-12-09T16:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN ELSE DELETE SYNTAX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907171#M358135</link>
      <description>&lt;P&gt;You could just recode leveraging a feature of Proc Format.&amp;nbsp; &amp;nbsp;Your code will begin where it says&amp;nbsp;&lt;CODE class=" language-sas"&gt;/* Start here */&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;You don't really need to create the Location variable unless you wish to export the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data yyy;                                         
    input GEOID desc $20.;                       
datalines;       
38001 Adams County
38003 Barnes County
38005 Benson County
38007 Billings County
38009 Bottineau County
38011 Bowman County
;
proc print;
run;
/* Start here */
data crtfmt;                                        
    set yyy;                                       
    start=GEOID;                                 
    label=desc;                                     
    fmtname='geof';                                
run;                                               
 
proc format library=work cntlin=crtfmt fmtlib;      
    select geof;                                   
run;
Data xxx;
   set yyy;
      LOCATION=put(GEOID,geof.) ;
run;
proc print;
ID GEOID;
var LOCATION;
run; 
/* End */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1702149660458.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91101iED44156AA4108E79/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1702149660458.png" alt="ghosh_0-1702149660458.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2023 19:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907171#M358135</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2023-12-09T19:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN ELSE DELETE SYNTAX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907177#M358137</link>
      <description>&lt;P&gt;That's an example where using formats is beneficial.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78622"&gt;@ghosh&lt;/a&gt;&amp;nbsp;is basically proposing the same but using a table as source for the format instead of an explicit definition. I felt for your use case and assumed level of SAS expertise below syntax is likely easier to absorb.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value GeoId2County
    38001="Adams County"
    38003="Barnes County"
    38005="Benson County"
    38007="Billings County"
    38009="Bottineau County"
    38011="Bowman County"
    38013="Burke County"
    38015="Burleigh County"
    38017="Cass County"
    38019="Cavalier County"
    38021="Dickey County"
    38023="Divide County"
    38025="Dunn County"
    38027="Eddy County"
    38029="Emmons County"
    38031="Foster County"
    38033="Golden Valley County"
    38035="Grand Forks County"
    38037="Grant County"
    38039="Griggs County"
    38041="Hettinger County"
    38043="Kidder County"
    38045="LaMoure County"
    38047="Logan County"
    38049="McHenry County"
    38051="McIntosh County"
    38053="McKenzie County"
    38055="McLean County"
    38057="Mercer County"
    38059="Morton County"
    38061="Mountrail County"
    38063="Nelson County"
    38065="Oliver County"
    38067="Pembina County"
    38069="Pierce County"
    38071="Ramsey County"
    38073="Ransom County"
    38075="Renville County"
    38077="Richland County"
    38079="Rolette County"
    38081="Sargent County"
    38083="Sheridan County"
    38085="Sioux County"
    38087="Slope County"
    38089="Stark County"
    38091="Steele County"
    38093="Stutsman County"
    38095="Towner County"
    38097="Traill County"
    38099="Walsh County"
    38101="Ward County"
    38103="Wells County"
    38105="Williams County"
    other=" "
    ;
run;

data want;
  set have;
  if put(geoid,GeoId2County.) = " " then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2023 03:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907177#M358137</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-10T03:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN ELSE DELETE SYNTAX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907185#M358139</link>
      <description>&lt;P&gt;You may want to investigate use of the FIPS related functions if you are looking for North Dakota areas.&lt;/P&gt;
&lt;P&gt;Although only the the first two digits would identify a state.&lt;/P&gt;
&lt;P&gt;I might suggest this for the filter.&lt;/P&gt;
&lt;PRE&gt;data xxx;
   set yyy;
   if fipstate(floor(geoid/1000))='ND';&lt;BR /&gt;
run;&lt;/PRE&gt;
&lt;P&gt;You should also have a data set SASHELP.Zipcode that has a county level FIPS code in the variable County that is the numeric county number that the FIPS codes use and the COUNTYNM has the name of the county.&lt;/P&gt;
&lt;P&gt;I use these pieces of information to make custom formats so I can display county names based on either the FIPS or ZIP which is again a numeric value.&lt;/P&gt;
&lt;P&gt;I have custom numeric and character versions so I don't have to deal with as many conversions when provided external data in either format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2023 07:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-DELETE-SYNTAX/m-p/907185#M358139</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-10T07:00:39Z</dc:date>
    </item>
  </channel>
</rss>

