<?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: Split a joined up UK post code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531334#M145407</link>
    <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if lengthn(pc)=6 then do;
    ...
  end;
  else do;
    ...
  end;
run;&lt;/PRE&gt;
&lt;P&gt;You may not need the do blocks, thats just for illustration.&amp;nbsp; To note, its sometimes better to code little bit each time, so break off part one and part two then combine in another step - just makes reading the code much simpler e.g.:&lt;/P&gt;
&lt;PRE&gt;data want (drop=last first);
  set have;
  last=substr(pc,lengthn(pc)-2);
  first=substr(pc,1,lengthn(pc)-3);
  want=catx(' ',first,last);
run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Jan 2019 11:29:10 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2019-01-30T11:29:10Z</dc:date>
    <item>
      <title>Split a joined up UK post code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531305#M145399</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a fairly newbie to SAS coding so I apologise in advance for any errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset where one of the variables (poscode) displays the UK postcode. However the post code is joined up i.e&amp;nbsp; it will display as BD181PZ and I would like it to display BD18 1PZ instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have managed to get the last 3 characters by using the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Post_Code= substr(Postcode,length(Postcode)-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Would anyone be able to help with splitting the post code please?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thanks in advance&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Nandeep&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 10:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531305#M145399</guid>
      <dc:creator>Nandeep</dc:creator>
      <dc:date>2019-01-30T10:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Split a joined up UK post code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531312#M145401</link>
      <description>&lt;P&gt;Assumes its is always 3 characters at end:&lt;/P&gt;
&lt;PRE&gt;data want;
  pc='BD181PZ';
  want=catx(' ',substr(pc,1,lengthn(pc)-2),substr(pc,lengthn(pc)-2,3));
run;&lt;/PRE&gt;
&lt;P&gt;You could also check lengthn() if it is 6 then split at char 4, if 7 then split at 7.&amp;nbsp; Various other methods.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 10:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531312#M145401</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-30T10:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Split a joined up UK post code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531331#M145405</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Assumes its is always 3 characters at end:&lt;/P&gt;&lt;PRE&gt;data want;
  pc='BD181PZ';
  want=catx(' ',substr(pc,1,lengthn(pc)-2),substr(pc,lengthn(pc)-2,3));
run;&lt;/PRE&gt;&lt;P&gt;You could also check lengthn() if it is 6 then split at char 4, if 7 then split at 7.&amp;nbsp; Various other methods.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thank you very much I just altered the above code to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Post_Code= catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,substr(Postcode,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,lengthn(Postcode)-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;),substr(Postcode,lengthn(Postcode)-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;and this seemed to have worked as having a -2 in the first set of brackets was bringing back too many characters.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;thanks once again&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Nandeep&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 11:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531331#M145405</guid>
      <dc:creator>Nandeep</dc:creator>
      <dc:date>2019-01-30T11:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Split a joined up UK post code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531332#M145406</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Assumes its is always 3 characters at end:&lt;/P&gt;&lt;PRE&gt;data want;
  pc='BD181PZ';
  want=catx(' ',substr(pc,1,lengthn(pc)-2),substr(pc,lengthn(pc)-2,3));
run;&lt;/PRE&gt;&lt;P&gt;You could also check lengthn() if it is 6 then split at char 4, if 7 then split at 7.&amp;nbsp; Various other methods.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;just out of interest what would the syntax be for the lenthn and split method?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nandeep&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 11:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531332#M145406</guid>
      <dc:creator>Nandeep</dc:creator>
      <dc:date>2019-01-30T11:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Split a joined up UK post code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531334#M145407</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if lengthn(pc)=6 then do;
    ...
  end;
  else do;
    ...
  end;
run;&lt;/PRE&gt;
&lt;P&gt;You may not need the do blocks, thats just for illustration.&amp;nbsp; To note, its sometimes better to code little bit each time, so break off part one and part two then combine in another step - just makes reading the code much simpler e.g.:&lt;/P&gt;
&lt;PRE&gt;data want (drop=last first);
  set have;
  last=substr(pc,lengthn(pc)-2);
  first=substr(pc,1,lengthn(pc)-3);
  want=catx(' ',first,last);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jan 2019 11:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531334#M145407</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-30T11:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Split a joined up UK post code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531337#M145408</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;PRE&gt;data want;
  set have;
  if lengthn(pc)=6 then do;
    ...
  end;
  else do;
    ...
  end;
run;&lt;/PRE&gt;&lt;P&gt;You may not need the do blocks, thats just for illustration.&amp;nbsp; To note, its sometimes better to code little bit each time, so break off part one and part two then combine in another step - just makes reading the code much simpler e.g.:&lt;/P&gt;&lt;PRE&gt;data want (drop=last first);
  set have;
  last=substr(pc,lengthn(pc)-2);
  first=substr(pc,1,lengthn(pc)-3);
  want=catx(' ',first,last);
run;&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;thank you very much for your help and explanation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nandeep&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 11:36:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-a-joined-up-UK-post-code/m-p/531337#M145408</guid>
      <dc:creator>Nandeep</dc:creator>
      <dc:date>2019-01-30T11:36:30Z</dc:date>
    </item>
  </channel>
</rss>

