<?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: Delete observations with wrong zip code format in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Delete-observations-with-wrong-zip-code-format/m-p/377200#M65440</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if
  length(postcode) = 7 and
  notdigit(substr(postcode,1,4)) = 0 and
  substr(postcode,5,1) = ' '
;
PC4 = input(substr(postcode,1,4),4.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might add code in the subsetting if that checks for allowed letters in substr(postcode,6,2).&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jul 2017 08:11:46 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-07-19T08:11:46Z</dc:date>
    <item>
      <title>Delete observations with wrong zip code format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-observations-with-wrong-zip-code-format/m-p/377197#M65439</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large dataset with client information. Zip codes have the following format: 1234 ZT. That is 4 digits, followed by a space and 2 letters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to extract the first four digits AND delete any observations that have the wrong format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; work.clients;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;set&lt;/SPAN&gt; work.clients;&lt;/P&gt;&lt;P class="p1"&gt;PC4_=substr(POSTCODE,&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;,&lt;SPAN class="s3"&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/SPAN&gt;);&lt;/P&gt;&lt;P class="p1"&gt;PC4=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P class="p1"&gt;PC4=input(PC4_,&lt;SPAN class="s3"&gt;&lt;STRONG&gt;8.&lt;/STRONG&gt;&lt;/SPAN&gt;);&lt;/P&gt;&lt;P class="p3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s4"&gt;This works well, but how do I delete the observations with the wrong format?&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s4"&gt;Thanks,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="s4"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 07:53:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-observations-with-wrong-zip-code-format/m-p/377197#M65439</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-07-19T07:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations with wrong zip code format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-observations-with-wrong-zip-code-format/m-p/377200#M65440</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if
  length(postcode) = 7 and
  notdigit(substr(postcode,1,4)) = 0 and
  substr(postcode,5,1) = ' '
;
PC4 = input(substr(postcode,1,4),4.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might add code in the subsetting if that checks for allowed letters in substr(postcode,6,2).&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 08:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-observations-with-wrong-zip-code-format/m-p/377200#M65440</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-19T08:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations with wrong zip code format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-observations-with-wrong-zip-code-format/m-p/377209#M65442</link>
      <description>&lt;P&gt;A regular expression should do the trick here&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm=",";
	input code $;
	datalines;
1234 ZT
5678 AB
Q123 AB
2345 4R
;
run;

data want(drop=pattern);
	set have;
	if _n_=1 then pattern=prxparse("/\d{4}\s[A-Z]{2}/");
	if not prxmatch(pattern, code) then delete;
	pc4=substr(code,1,4);
	retain pattern;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jul 2017 08:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-observations-with-wrong-zip-code-format/m-p/377209#M65442</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-07-19T08:52:11Z</dc:date>
    </item>
  </channel>
</rss>

