<?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: Add leading zero based on the number of numbers for that value in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278233#M58853</link>
    <description>&lt;P&gt;You've received some great options from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/47932"&gt;@slchen﻿&lt;/a&gt;. &amp;nbsp;I don't have a better way, but I'll offer this: I think you should consider using leading 0s for ALL of your values, not just those that exceed a 1-digit length. &amp;nbsp;I think you'll find the consistency is better for sorting and reporting. &amp;nbsp;I don't know the context of your application here, but what if today you have X_1 - X_5, but tomorrow your Xs grow to X_11? &amp;nbsp;The consistency and predictability of the values might help you in the long run.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jun 2016 15:59:17 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2016-06-17T15:59:17Z</dc:date>
    <item>
      <title>Add leading zero based on the number of numbers for that value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278206#M58848</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a situation where I have data like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;X_1
X_2
X_3
X_4
X_5
Z_1
Z_2
Z_3
Z_4
Z_5
Z_6
Z_7
Z_8
Z_9
Z_10
Z_11&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where the data has a value over 9 I need 1-9 to have a leading zero. Based on the above data I need this to happen&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;X_1
X_2
X_3
X_4
X_5
Z_01
Z_02
Z_03
Z_04
Z_05
Z_06
Z_07
Z_08
Z_09
Z_10
Z_11&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is the code I'm starting to work with.&amp;nbsp; This column of data can have values with no '_' or and '_' with characters after.&amp;nbsp; I only want to do this for values where there are numbers after the '_'.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x ;
	set temp ;
	start = scan(val, 1, '_') ;
	end = scan(val, 2, '_') ;
	if end ne '' and ANYALPHA(end) = 0 then output ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you for any help you can give me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 14:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278206#M58848</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2016-06-17T14:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zero based on the number of numbers for that value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278223#M58851</link>
      <description>&lt;P&gt;You have to find the W(idth) for each VAL group X and Z. &amp;nbsp;Then you can creat the VAL with the proper number of leading zeros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data val;
   input val:$8.;
   cards;
X_1
X_4
X_5
Z_1
Z_2
Z_6
Z_7
Z_8
Z_9
Z_10
Z_11
X_2
X_3
Z_3
Z_4
Z_5
Q_1
Q_200
;;;;
   run;
data valv / view=valv;
   set val;
   length valgroup $32;
   valgroup = scan(val,1,'_');
   valnum   = input(scan(val,-1,'_'),8.);
   run;
proc sort data=valv out=val2;
   by valgroup valnum;
   run;
proc print;
   run;
proc summary data=val2;
   by valgroup;
   output out=max(drop=_:) max(valnum)=max;
   run;
data val3;
   merge val2 max;
   by valgroup;
   w = floor(log10(max)+1);
   length new_val $10;
   new_val = catx('_',valgroup,putn(valnum,'Z',w));
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3664i8B2E85BC0147242B/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 15:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278223#M58851</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-06-17T15:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zero based on the number of numbers for that value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278230#M58852</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input x $;&lt;BR /&gt;cards;&lt;BR /&gt;X_1&lt;BR /&gt;X_2&lt;BR /&gt;X_3&lt;BR /&gt;X_4&lt;BR /&gt;X_5&lt;BR /&gt;Z_1&lt;BR /&gt;Z_2&lt;BR /&gt;Z_3&lt;BR /&gt;Z_4&lt;BR /&gt;Z_5&lt;BR /&gt;Z_6&lt;BR /&gt;Z_7&lt;BR /&gt;Z_8&lt;BR /&gt;Z_9&lt;BR /&gt;Z_10&lt;BR /&gt;Z_11&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;x=ifc(index(x,'Z')&amp;gt;0, catx('_',scan(x,1,'_'),put(input(scan(x,2,'_'),2.),z2.)),x);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 15:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278230#M58852</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2016-06-17T15:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zero based on the number of numbers for that value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278233#M58853</link>
      <description>&lt;P&gt;You've received some great options from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/47932"&gt;@slchen﻿&lt;/a&gt;. &amp;nbsp;I don't have a better way, but I'll offer this: I think you should consider using leading 0s for ALL of your values, not just those that exceed a 1-digit length. &amp;nbsp;I think you'll find the consistency is better for sorting and reporting. &amp;nbsp;I don't know the context of your application here, but what if today you have X_1 - X_5, but tomorrow your Xs grow to X_11? &amp;nbsp;The consistency and predictability of the values might help you in the long run.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 15:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278233#M58853</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2016-06-17T15:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zero based on the number of numbers for that value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278235#M58854</link>
      <description>Thank you Chris.  I'm going through the above solutions now.  The reason I can't do that is that I will be joining them based on this value to another table that is coming from someone else and they only add the zero when the count is greater then 9.  Thanks again.  I'll reply back and accept the solution as soon as I get it resolved.  Thank you</description>
      <pubDate>Fri, 17 Jun 2016 16:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-leading-zero-based-on-the-number-of-numbers-for-that-value/m-p/278235#M58854</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2016-06-17T16:01:24Z</dc:date>
    </item>
  </channel>
</rss>

