<?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: Create 4 digit length in the text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632159#M187391</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the following approach to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set test;
	length result2 $ 200;
	if input(Name, 8.) &amp;lt; 1000 then result2 = put(input(Name, 8.), z4.);
	else result2 = Name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-03-14 à 17.17.08.png" style="width: 151px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36881iF54E3386145F3411/image-size/small?v=v2&amp;amp;px=200" role="button" title="Capture d’écran 2020-03-14 à 17.17.08.png" alt="Capture d’écran 2020-03-14 à 17.17.08.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
    <pubDate>Sat, 14 Mar 2020 16:17:30 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-03-14T16:17:30Z</dc:date>
    <item>
      <title>Create 4 digit length in the text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632156#M187389</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sample test dataset.&amp;nbsp; I would like to put 0 in front of the digit shown the result column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
      infile datalines dsd;
  input Name : $300. Result : $200. ;
datalines;
	01,  0001
	4000, 4000,
	78790, 78790,
	2, 0002,
	111, 0111
;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Mar 2020 16:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632156#M187389</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-03-14T16:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create 4 digit length in the text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632157#M187390</link>
      <description>Read it in as a number and use the Z4 format which will add zeros. &lt;BR /&gt;&lt;BR /&gt;results_padded = put(input(result, 8.), z4.);&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 14 Mar 2020 16:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632157#M187390</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-14T16:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create 4 digit length in the text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632159#M187391</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the following approach to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set test;
	length result2 $ 200;
	if input(Name, 8.) &amp;lt; 1000 then result2 = put(input(Name, 8.), z4.);
	else result2 = Name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-03-14 à 17.17.08.png" style="width: 151px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36881iF54E3386145F3411/image-size/small?v=v2&amp;amp;px=200" role="button" title="Capture d’écran 2020-03-14 à 17.17.08.png" alt="Capture d’écran 2020-03-14 à 17.17.08.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2020 16:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632159#M187391</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-14T16:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create 4 digit length in the text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632160#M187392</link>
      <description>&lt;P&gt;The code change 78790 to 79E3.&amp;nbsp; Not the one I want.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2020 16:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632160#M187392</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-03-14T16:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create 4 digit length in the text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632162#M187394</link>
      <description>&lt;P&gt;You can make your own format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  picture myfmt
     0 -    9999='9999'
 99999&amp;lt;-   99999='99999'
 999999&amp;lt;-  999999='999999';
run;

data x;
  input x;
  format x myfmt. ;
  format x mfmt. ;
datalines;
01
4000
78790
2
111
;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited change.&amp;nbsp; The PICTURE statement above replaced this VALUE statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  value myfmt
      0 -  9999=[z4.] 
  99999&amp;amp;lt;- 99999=[z5.]
 999999&amp;amp;lt;-999999=[z6.]  ;
&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Mar 2020 16:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632162#M187394</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-03-14T16:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create 4 digit length in the text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632163#M187395</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sample test dataset.&amp;nbsp; I would like to put 0 in front of the digit shown the result column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
      infile datalines dsd;
  input Name : $300. Result : $200. ;
datalines;
	01,  0001
	4000, 4000,
	78790, 78790,
	2, 0002,
	111, 0111
;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you actually have the 8 leading spaces in the values of NAME implied by starting your lines of data in column 9 instead of column 1?&amp;nbsp; If so then using the $ informat instead of the $CHAR informat will eliminate the leading spaces.&amp;nbsp; Worse if those lines of data start with a tab character you might end up with the actual tab character in the data if you are using SAS/Studio instead of Display Manager to edit and submit your SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming the values of NAME do not have either leading spaces, embedded space (or tabs), then you could just right align the values and replace the leading spaces with zeros.&amp;nbsp; Adjust the length of the right aligned value to have a minimum of 4 characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;result = translate(putc(name,cats('$',max(4,length(name)),'.-R')),'0',' ');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Note this will convert a missing value (all blank value) into '0000'.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2020 18:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-4-digit-length-in-the-text/m-p/632163#M187395</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-14T18:44:26Z</dc:date>
    </item>
  </channel>
</rss>

