<?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: Leading 0 in string where there are also non-numeric values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695244#M212129</link>
    <description>&lt;P&gt;will this work if one of the variable values is the character string "unknown"?&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2020 15:42:43 GMT</pubDate>
    <dc:creator>raivester</dc:creator>
    <dc:date>2020-10-29T15:42:43Z</dc:date>
    <item>
      <title>Leading 0 in string where there are also non-numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695242#M212127</link>
      <description>&lt;P&gt;Hello--&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recently received a data set with Var1 values: '1'&amp;nbsp; '2'&amp;nbsp; '3'&amp;nbsp; '4'&amp;nbsp; '5'&amp;nbsp; '10'&amp;nbsp; '11'&amp;nbsp; '12'&amp;nbsp; '13'&amp;nbsp; '14'&amp;nbsp; '15'&amp;nbsp; 'unknown.'&amp;nbsp; This variable is obviously character, but I need leading 0s on the digits that are less than 10. Is there an elegant way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695242#M212127</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-10-29T15:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Leading 0 in string where there are also non-numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695243#M212128</link>
      <description>Want = put(input(var1, 8.), z2.);&lt;BR /&gt;&lt;BR /&gt;Or convert it to a number and display with Z2 format. &lt;BR /&gt;&lt;BR /&gt;want = input(var1, 8.);&lt;BR /&gt;format want Z2.;</description>
      <pubDate>Thu, 29 Oct 2020 15:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695243#M212128</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-29T15:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Leading 0 in string where there are also non-numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695244#M212129</link>
      <description>&lt;P&gt;will this work if one of the variable values is the character string "unknown"?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695244#M212129</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-10-29T15:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Leading 0 in string where there are also non-numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695245#M212130</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326526"&gt;@raivester&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd suggest this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if lengthn(var1)=1 then var1='0'||var1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(I use LENGTHN, not LENGTH, because missing values should not be replaced by zeros.)&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695245#M212130</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-29T15:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Leading 0 in string where there are also non-numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695246#M212131</link>
      <description>No, but you could add an IF to conditionally execute the conversion or change unknown to show as missing or a SAS special missing value.</description>
      <pubDate>Thu, 29 Oct 2020 15:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695246#M212131</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-29T15:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Leading 0 in string where there are also non-numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695248#M212133</link>
      <description>&lt;P&gt;Ahh! Good thinking. Thanks for the help&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695248#M212133</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-10-29T15:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Leading 0 in string where there are also non-numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695249#M212134</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var1 $;
datalines;
1
2
3
4
5
6
11
12
13
14
15
unknown
;

data want;
set have;
if anyalpha(var1) = 0
then var1 = put(input(var1,best.),z2. -l);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695249#M212134</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-29T15:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Leading 0 in string where there are also non-numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695263#M212142</link>
      <description>&lt;P&gt;Do you expect to need to do arithmetic with these values? Or model with the numeric value ?&lt;/P&gt;
&lt;P&gt;If so, then read them as numeric so the unknown are missing and if you need a leading zero use a Z2. format.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 16:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-0-in-string-where-there-are-also-non-numeric-values/m-p/695263#M212142</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-29T16:30:21Z</dc:date>
    </item>
  </channel>
</rss>

