<?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: Padding of character variable with zeroes. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424406#M68177</link>
    <description>&lt;P&gt;I have some mixed values in the character variable for example,&amp;nbsp; 0.155322 and -0.155322&lt;/P&gt;&lt;P&gt;So however in my output I want the value to be displayed as&amp;nbsp;&lt;SPAN&gt;0.1553 and&amp;nbsp;&lt;/SPAN&gt; -0.1553 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used want=put(input(charvar,best.),z7.4);&lt;/P&gt;&lt;P&gt;To accomodate the negative sign I used 7.4 format but this is not what I want... I want just 6.4 format assigned on my values...so if I use 6.4 format my values are displayed as&amp;nbsp;&lt;SPAN&gt;-.1553. thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jan 2018 19:34:21 GMT</pubDate>
    <dc:creator>Aidaan_10</dc:creator>
    <dc:date>2018-01-02T19:34:21Z</dc:date>
    <item>
      <title>Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424395#M68170</link>
      <description>&lt;P&gt;I have a question. My data has following values:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;zip&lt;/P&gt;&lt;P&gt;123456789&lt;/P&gt;&lt;P&gt;-123456789&lt;/P&gt;&lt;P&gt;1234&lt;/P&gt;&lt;P&gt;-.234&lt;/P&gt;&lt;P&gt;12345&lt;/P&gt;&lt;P&gt;-.23456789&lt;/P&gt;&lt;P&gt;12345&lt;/P&gt;&lt;P&gt;12345&lt;/P&gt;&lt;P&gt;1234&lt;/P&gt;&lt;P&gt;123456789&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get a single variable with:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;first 6 digit from 9 digit zip var;&lt;/LI&gt;&lt;LI&gt;add leading zero where there is 1 less&amp;nbsp; digit zip and&lt;/LI&gt;&lt;LI&gt;keep 6 digit zip value as it is.&lt;/LI&gt;&lt;LI&gt;I tried this but it doesn't give me expected results. So&amp;nbsp;I tried increasing the zw.d format to 7.3 and its working for values with negative sign but the other values are not correct. Expected format is 6.3.&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; padded &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;charvar&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;best&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;zw.d&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 19:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424395#M68170</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2018-01-02T19:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424397#M68171</link>
      <description>&lt;P&gt;You need to replace w and d with numeric values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you want Z5. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;BR /&gt;
&lt;UL&gt;
&lt;LI&gt;add leading zero where there is 1 less&amp;nbsp; digit zip and&lt;/LI&gt;
&lt;/UL&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's not clear what that means...&lt;/P&gt;
&lt;P&gt;It would likely help if you showed what you want as output from this data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174192"&gt;@Aidaan_10&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have a question. My data has following values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;zip&lt;/P&gt;
&lt;P&gt;123456789&lt;/P&gt;
&lt;P&gt;-123456789&lt;/P&gt;
&lt;P&gt;1234&lt;/P&gt;
&lt;P&gt;-.234&lt;/P&gt;
&lt;P&gt;12345&lt;/P&gt;
&lt;P&gt;-.23456789&lt;/P&gt;
&lt;P&gt;12345&lt;/P&gt;
&lt;P&gt;12345&lt;/P&gt;
&lt;P&gt;1234&lt;/P&gt;
&lt;P&gt;123456789&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to get a single variable with:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;first 6 digit from 9 digit zip var;&lt;/LI&gt;
&lt;LI&gt;add leading zero where there is 1 less&amp;nbsp; digit zip and&lt;/LI&gt;
&lt;LI&gt;keep 6 digit zip value as it is.&lt;/LI&gt;
&lt;LI&gt;I tried this but it doesn't give me expected results. So&amp;nbsp;I tried increasing the zw.d format to 7.3 and its working for values with negative sign but the other values are not correct. Expected format is 6.3.
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; padded &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;charvar&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;best&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;zw.d&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 19:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424397#M68171</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-02T19:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424398#M68172</link>
      <description>&lt;P&gt;I think it's unclear to me at least exactly what your rules are.&amp;nbsp; You mention 'digits' and have (and want, apparently?) decimals, but you don't discuss how they (and negatives) count towards digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you put the "desired" for all of these?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The initial problem is that INPUT works off character, so you have to first PUT your number to a character before anything else happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One possibility is the following; it would be&amp;nbsp;helpful to explain where this is not correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input zip;
datalines;
123456789
-123456789
1234
-.234
12345
-.23456789
12345
12345
1234
123456789
;;;;
run;


data want;
  set have;
  zip_c = put(input(substr(put(zip,12.3 -l),1,6),6.),z6.3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice I first PUT the zip to a large-enough string; then I substring it to 6 digits; then I input it; then I put it back with zero padding.&amp;nbsp; This doesn't exactly match what you indicate though, but&amp;nbsp;it depends on how the negative sign and decimal are supposed to work, really.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 19:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424398#M68172</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2018-01-02T19:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes. [how to improve your question]</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424399#M68173</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174192"&gt;@Aidaan_10&lt;/a&gt;,&lt;/P&gt;&lt;BR /&gt; &lt;P&gt;Your question requires more details before experts can help.&amp;nbsp;Can you revise your question to include more information?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Review this checklist:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Specify a meaningful subject line for your topic.&amp;nbsp; Avoid generic subjects like "need help," "SAS query," or "urgent."&lt;/LI&gt;
&lt;LI&gt;When appropriate, provide sample data in text or DATA step format.&amp;nbsp; See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;this article for one method&lt;/A&gt;&amp;nbsp;you can use.&lt;/LI&gt;
&lt;LI&gt;If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition.&amp;nbsp;Use the&amp;nbsp;&lt;STRONG&gt;Photos&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;button to include the image in your message.&lt;BR /&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 279px;"&gt;&lt;IMG src="https://kntur85557.i.lithium.com/t5/image/serverpage/image-id/16608i91A52F817EAC9A69/image-dimensions/279x150?v=1.0" width="279" height="150" alt="use_buttons.png" title="use_buttons.png" /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;It also helps to include an example (table or picture) of the result that you're trying to achieve.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;To edit your original message, select the "blue gear" icon at the top of the message and select&amp;nbsp;&lt;STRONG&gt;Edit Message&lt;/STRONG&gt;.&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;From there you can adjust the title and add more details to the body of the message.&amp;nbsp; Or, simply reply to this message with any additional information you can supply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 229px;"&gt;&lt;IMG src="https://kntur85557.i.lithium.com/t5/image/serverpage/image-id/16605iAC020BC79315B045/image-size/large?v=1.0&amp;amp;px=600" alt="edit_post.png" title="edit_post.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;SAS experts are eager to help -- help&amp;nbsp;&lt;EM&gt;them&lt;/EM&gt; by providing as much detail as you can.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-style:italic;font-size:smaller;"&gt;This prewritten response was triggered for you by fellow SAS Support Communities member &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/SPAN&gt;&lt;/P&gt;.</description>
      <pubDate>Tue, 02 Jan 2018 19:21:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424399#M68173</guid>
      <dc:creator>Community_Guide</dc:creator>
      <dc:date>2018-01-02T19:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424401#M68175</link>
      <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 19:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424401#M68175</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-02T19:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424403#M68176</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; - that link is incomplete; here's the full one:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;</description>
      <pubDate>Tue, 02 Jan 2018 19:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424403#M68176</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2018-01-02T19:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424406#M68177</link>
      <description>&lt;P&gt;I have some mixed values in the character variable for example,&amp;nbsp; 0.155322 and -0.155322&lt;/P&gt;&lt;P&gt;So however in my output I want the value to be displayed as&amp;nbsp;&lt;SPAN&gt;0.1553 and&amp;nbsp;&lt;/SPAN&gt; -0.1553 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used want=put(input(charvar,best.),z7.4);&lt;/P&gt;&lt;P&gt;To accomodate the negative sign I used 7.4 format but this is not what I want... I want just 6.4 format assigned on my values...so if I use 6.4 format my values are displayed as&amp;nbsp;&lt;SPAN&gt;-.1553. thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 19:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424406#M68177</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2018-01-02T19:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424411#M68179</link>
      <description>Please give the full list of values in the final desired datastep.  It is still unclear exactly what you mean, at least to me, particularly in relation to - and . as part of the values. (It's also confusing here you use "zip" as the variable name - in the US, that would be "zip code" which is a common field that _is_ zero padded, but wouldn't have negative or decimal, so perhaps this is part of the confusion.)</description>
      <pubDate>Tue, 02 Jan 2018 19:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424411#M68179</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2018-01-02T19:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424681#M68221</link>
      <description>&lt;P&gt;Hello Snoopy...thanks for your reply and sorry for the confusion.&lt;/P&gt;&lt;P&gt;I attached a file below where the two dataset's are produced by means procedure and the zip&amp;nbsp;data was just an example which was inappropriate I guess..the&amp;nbsp; dataset which is below, has all of the correct values in all the variables however in the above dataset, please have a look at chg_minc character variable&amp;nbsp; that has value of -.278. I want to pad this value with zero after negative sign so it can be displayed as -0.278 so I used this line of code want=put(input(min,best.),z6.3) and I am getting the right answer&lt;/P&gt;&lt;P&gt;but however the values where there is no negative sign I want the format to be 5.3 and not 6.3 so what's&amp;nbsp;the best way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 19:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424681#M68221</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2018-01-03T19:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Padding of character variable with zeroes.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424687#M68226</link>
      <description>&lt;P&gt;I feel like this isn't een the original question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can nest formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value myfmt
low - 0 = [z5.3]
0-high = [6.2];
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jan 2018 19:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Padding-of-character-variable-with-zeroes/m-p/424687#M68226</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-03T19:20:04Z</dc:date>
    </item>
  </channel>
</rss>

