<?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: Help adding leading zeros to zipcode with multiple instances per row with delimiter in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/936295#M42078</link>
    <description>&lt;P&gt;First, if possible provide the starting data in the form of data step code as shown below.&lt;/P&gt;
&lt;P&gt;Second paste the code in a text box as sometimes code pasted into the main message windows will not run because of reformatting done by the forum software.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for your example data:&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines truncover;
   input zip_code_have	$30.;
datalines4;
916	
37322	
3452	
5701-4012
98682	
12953	
46311	
1234; 1234; 23456-4444	
84032; 84095; 84065; 84065	
;;;;

data want;
   set have;
   /* need to define a length for the zip_code_want
      long enough to hold multiple inserted characters
      such as missing leading 0 plus the delimiters
   */
   length zip_code_want $ 50 z_temp $ 10.;
   /* get number of zip codes in file*/
   do i=1 to countw(zip_code_have,';');
      /* get ONE zip*/
      z_temp=scan(zip_code_have,i,';');
      if index(z_temp,'-')&amp;gt;0 then z_temp=scan(z_temp,1,'-');
      z_temp =put(input(strip(z_temp),5.),z5.);
      zip_code_want=catx('; ',zip_code_want,z_temp);
   end;
   drop z_temp i;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2024 22:32:01 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-07-18T22:32:01Z</dc:date>
    <item>
      <title>Help adding leading zeros to zipcode with multiple instances per row with delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/936293#M42077</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have what is probably a very basic question, but I am new to SAS and would love some help figuring it out.&amp;nbsp; I have a file with a list of zip codes, but there could be multiple zip codes associated with each row of data.&amp;nbsp; (If there are multiple zip codes in a row they are separated by a semi-colon.)&amp;nbsp; The way the data currently looks is demonstrated in the column below labeled "zip_code_have" and is a CHAR variable.&amp;nbsp;I need to: 1) add missing zeros to the zip codes that do not have them (in some cases it could be one zero, and others it could be two because there are some territory zip codes in there) and 2) remove the "-" and last four digits of the zip codes that have them.&amp;nbsp; (So it looks like the column "zip_code_want". )&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;zip_code_have&lt;/TD&gt;&lt;TD&gt;zip_code_want&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;916&lt;/TD&gt;&lt;TD&gt;00916&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37322&lt;/TD&gt;&lt;TD&gt;37322&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3452&lt;/TD&gt;&lt;TD&gt;03452&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5701-4012&lt;/TD&gt;&lt;TD&gt;05701&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;98682&lt;/TD&gt;&lt;TD&gt;98682&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12953&lt;/TD&gt;&lt;TD&gt;12953&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;46311&lt;/TD&gt;&lt;TD&gt;46311&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1234; 1234; 23456-4444&lt;/TD&gt;&lt;TD&gt;01234; 01234; 23456&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;84032; 84095; 84065; 84065&lt;/TD&gt;&lt;TD&gt;84032; 84095; 84065; 84065&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be greatly appreciated!&amp;nbsp; Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 22:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/936293#M42077</guid>
      <dc:creator>Ae204</dc:creator>
      <dc:date>2024-07-18T22:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help adding leading zeros to zipcode with multiple instances per row with delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/936295#M42078</link>
      <description>&lt;P&gt;First, if possible provide the starting data in the form of data step code as shown below.&lt;/P&gt;
&lt;P&gt;Second paste the code in a text box as sometimes code pasted into the main message windows will not run because of reformatting done by the forum software.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for your example data:&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines truncover;
   input zip_code_have	$30.;
datalines4;
916	
37322	
3452	
5701-4012
98682	
12953	
46311	
1234; 1234; 23456-4444	
84032; 84095; 84065; 84065	
;;;;

data want;
   set have;
   /* need to define a length for the zip_code_want
      long enough to hold multiple inserted characters
      such as missing leading 0 plus the delimiters
   */
   length zip_code_want $ 50 z_temp $ 10.;
   /* get number of zip codes in file*/
   do i=1 to countw(zip_code_have,';');
      /* get ONE zip*/
      z_temp=scan(zip_code_have,i,';');
      if index(z_temp,'-')&amp;gt;0 then z_temp=scan(z_temp,1,'-');
      z_temp =put(input(strip(z_temp),5.),z5.);
      zip_code_want=catx('; ',zip_code_want,z_temp);
   end;
   drop z_temp i;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 22:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/936295#M42078</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-18T22:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help adding leading zeros to zipcode with multiple instances per row with delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/936315#M42079</link>
      <description>&lt;P&gt;While you're at it, consider splitting those multiple entries into multiple observations. Maxim 19: Long Beats Wide.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2024 08:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/936315#M42079</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-07-19T08:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help adding leading zeros to zipcode with multiple instances per row with delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/937967#M42144</link>
      <description>&lt;P&gt;This worked perfectly - thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 15:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-adding-leading-zeros-to-zipcode-with-multiple-instances-per/m-p/937967#M42144</guid>
      <dc:creator>Ae204</dc:creator>
      <dc:date>2024-08-01T15:10:04Z</dc:date>
    </item>
  </channel>
</rss>

