<?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 Adding Leading Zero to  Character Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780132#M248551</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm setting the zip code to be a 5-digit character variable, and adding a leading zero if there are only 4 digits.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data survey;
	infile '/home/uid/zip.csv' delimiter=',' missover firstobs=2 dsd;
        format Zip_Code $5.;
        input Zip_Code $;&lt;BR /&gt;&lt;BR /&gt;/* I've tried all 3 but none of them worked. */
        Zip_Code = put(input(Zip_Code, best12.), z5.);
	    Zip_Code = put(Zip_Code, z5. -L);
	    Zip_Code = put(Zip_Code, z5.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the error comes out every time&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV id="sasLogError1_1636884956382" class="sasError"&gt;Statement is not valid or it is used out of proper order.&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV class="sasError"&gt;Any hint or help? Thank you in advance!&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Sun, 14 Nov 2021 10:18:08 GMT</pubDate>
    <dc:creator>aabbccwyt</dc:creator>
    <dc:date>2021-11-14T10:18:08Z</dc:date>
    <item>
      <title>Adding Leading Zero to  Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780132#M248551</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm setting the zip code to be a 5-digit character variable, and adding a leading zero if there are only 4 digits.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data survey;
	infile '/home/uid/zip.csv' delimiter=',' missover firstobs=2 dsd;
        format Zip_Code $5.;
        input Zip_Code $;&lt;BR /&gt;&lt;BR /&gt;/* I've tried all 3 but none of them worked. */
        Zip_Code = put(input(Zip_Code, best12.), z5.);
	    Zip_Code = put(Zip_Code, z5. -L);
	    Zip_Code = put(Zip_Code, z5.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the error comes out every time&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV id="sasLogError1_1636884956382" class="sasError"&gt;Statement is not valid or it is used out of proper order.&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV class="sasError"&gt;Any hint or help? Thank you in advance!&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 14 Nov 2021 10:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780132#M248551</guid>
      <dc:creator>aabbccwyt</dc:creator>
      <dc:date>2021-11-14T10:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Leading Zero to  Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780134#M248553</link>
      <description>&lt;P&gt;Please post the complete log of that step.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 10:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780134#M248553</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-14T10:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Leading Zero to  Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780135#M248554</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292388"&gt;@aabbccwyt&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just ran the code below and it works fine...Note that I set the variable length to 5 by using the "length" statement and not by using the "format" statement. It does not explain the error you get. Perhaps you should try to narrow down where the error is originating from. Add some "put" statements to the code before each line or use the data step debugger.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	length Zip_code $ 5;
	Zip_Code = '1234';
	Zip_Code = put(input(Zip_Code, best12.), z5.);
	put Zip_Code=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Nov 2021 10:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780135#M248554</guid>
      <dc:creator>EyalGonen</dc:creator>
      <dc:date>2021-11-14T10:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Leading Zero to  Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780137#M248556</link>
      <description>Better post your data "/home/uid/zip.csv", so we can test it where is wrong .</description>
      <pubDate>Sun, 14 Nov 2021 11:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780137#M248556</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-11-14T11:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Leading Zero to  Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780140#M248557</link>
      <description>&lt;P&gt;Thank yall for your replies. The code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Zip_Code = put(input(Zip_Code, best12.), z5.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is correct. I got it wrong because of a typo. I will accept&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13766"&gt;@EyalGonen&lt;/a&gt;&amp;nbsp;answer so the topic will be closed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 13:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Leading-Zero-to-Character-Variable/m-p/780140#M248557</guid>
      <dc:creator>aabbccwyt</dc:creator>
      <dc:date>2021-11-14T13:47:35Z</dc:date>
    </item>
  </channel>
</rss>

