<?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 a field with 0 in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6754#M2169</link>
    <description>Your welcome.&lt;BR /&gt;
&lt;BR /&gt;
As a side note:&lt;BR /&gt;
&lt;BR /&gt;
It would be more efficient to simply store a number as a number, and then associate an appropriate format for that number with it.  A number is stored in binary, and in SAS, at present (per my understanding), consumes at most 8 bytes.   Your 18 character text number consumes 18 bytes.  All you need is a format associated with the number to make it report as 18 characters, padded with leading zeroes.&lt;BR /&gt;
&lt;BR /&gt;
DATA table;&lt;BR /&gt;
  set table;&lt;BR /&gt;
  format number z18.;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
or&lt;BR /&gt;
&lt;BR /&gt;
DATA table;&lt;BR /&gt;
  attrib number format=z18. informat=18.;&lt;BR /&gt;
  infile input_data;&lt;BR /&gt;
  input number;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
both the format and attrib statements can associate the z18. format to a field.&lt;BR /&gt;
then whenever SAS reports the value, it will print it as an 18 character ...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Using this method allows you to simply change the data representation with a format, as opposed to having to actually run through the data to change the textual representation.&lt;BR /&gt;
&lt;BR /&gt;
Formats can even impose a picture to a number:&lt;BR /&gt;
.ssn takes a 9 digit number and reports it as a social security number = 123-45-6789&lt;BR /&gt;
you could create a credit card format that injects dashes or spaces into a 16 digit number.&lt;BR /&gt;
&lt;BR /&gt;
Similarly informats can translate a textually entered "number" into a number.&lt;BR /&gt;
(312) 555-1234 could be input directly and stored as a binary number = 3125551234, and then reprinted as a European style phone number = 312.555.1234&lt;BR /&gt;
&lt;BR /&gt;
I would recommend reading the documentation for the format and attrib statements, and the proc format procedure.

null</description>
    <pubDate>Tue, 05 Feb 2008 13:59:43 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-02-05T13:59:43Z</dc:date>
    <item>
      <title>Padding a field with 0</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6751#M2166</link>
      <description>I have a filed that will be 9 to 12 numbers in length, example  954265478.  The field is in text format.  I need to pad the front of this number with 0 to make the total length of the field 18, 000000000954265478.  The length of my initial data wont always be 9, it can vary.  Does anyone have a suggestion on how I can do this?</description>
      <pubDate>Tue, 05 Feb 2008 13:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6751#M2166</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-05T13:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Padding a field with 0</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6752#M2167</link>
      <description>The easiest that I can think of is:&lt;BR /&gt;
&lt;BR /&gt;
data old_data;&lt;BR /&gt;
  length number $18;&lt;BR /&gt;
  set old_data;&lt;BR /&gt;
&lt;BR /&gt;
  number = put(input(number,18.),z18.);&lt;BR /&gt;
run;&lt;BR /&gt;
quit;

null</description>
      <pubDate>Tue, 05 Feb 2008 13:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6752#M2167</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-05T13:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Padding a field with 0</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6753#M2168</link>
      <description>Thank you very much</description>
      <pubDate>Tue, 05 Feb 2008 13:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6753#M2168</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-05T13:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Padding a field with 0</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6754#M2169</link>
      <description>Your welcome.&lt;BR /&gt;
&lt;BR /&gt;
As a side note:&lt;BR /&gt;
&lt;BR /&gt;
It would be more efficient to simply store a number as a number, and then associate an appropriate format for that number with it.  A number is stored in binary, and in SAS, at present (per my understanding), consumes at most 8 bytes.   Your 18 character text number consumes 18 bytes.  All you need is a format associated with the number to make it report as 18 characters, padded with leading zeroes.&lt;BR /&gt;
&lt;BR /&gt;
DATA table;&lt;BR /&gt;
  set table;&lt;BR /&gt;
  format number z18.;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
or&lt;BR /&gt;
&lt;BR /&gt;
DATA table;&lt;BR /&gt;
  attrib number format=z18. informat=18.;&lt;BR /&gt;
  infile input_data;&lt;BR /&gt;
  input number;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
both the format and attrib statements can associate the z18. format to a field.&lt;BR /&gt;
then whenever SAS reports the value, it will print it as an 18 character ...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Using this method allows you to simply change the data representation with a format, as opposed to having to actually run through the data to change the textual representation.&lt;BR /&gt;
&lt;BR /&gt;
Formats can even impose a picture to a number:&lt;BR /&gt;
.ssn takes a 9 digit number and reports it as a social security number = 123-45-6789&lt;BR /&gt;
you could create a credit card format that injects dashes or spaces into a 16 digit number.&lt;BR /&gt;
&lt;BR /&gt;
Similarly informats can translate a textually entered "number" into a number.&lt;BR /&gt;
(312) 555-1234 could be input directly and stored as a binary number = 3125551234, and then reprinted as a European style phone number = 312.555.1234&lt;BR /&gt;
&lt;BR /&gt;
I would recommend reading the documentation for the format and attrib statements, and the proc format procedure.

null</description>
      <pubDate>Tue, 05 Feb 2008 13:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6754#M2169</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-05T13:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Padding a field with 0</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6755#M2170</link>
      <description>If i use the format z18. and keep the field as a number will a Merge of that field or a Proc sql Left Join recognize this field if the field i am joining it with is text?</description>
      <pubDate>Tue, 05 Feb 2008 14:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6755#M2170</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-05T14:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Padding a field with 0</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6756#M2171</link>
      <description>I don't know.&lt;BR /&gt;
&lt;BR /&gt;
Ideally, all the data instances of a number are numeric.  But we can't always rely on that.&lt;BR /&gt;
&lt;BR /&gt;
If I were in this situation, I would have to experiment a bit.&lt;BR /&gt;
&lt;BR /&gt;
I do know that SAS can do and sometimes will do data conversions for numbers into text, and text into numbers, to match datatypes in conditional clauses.</description>
      <pubDate>Tue, 05 Feb 2008 15:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6756#M2171</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-05T15:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Padding a field with 0</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6757#M2172</link>
      <description>Chuck;&lt;BR /&gt;
&lt;BR /&gt;
This is the error message I get when I try and do a JOIN with a number field formated at z18. and a text field length $18&lt;BR /&gt;
&lt;BR /&gt;
ERROR: Expression using equals (=) has components that are of different data types.</description>
      <pubDate>Tue, 05 Feb 2008 15:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6757#M2172</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-05T15:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Padding a field with 0</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6758#M2173</link>
      <description>an SQL join can convert data types "on the fly". &lt;BR /&gt;
To achieve the same in a data step merge, use data step views to convert to the common data type.&lt;BR /&gt;
&lt;BR /&gt;
I hope you don't need to rely on a SAS numeric holding 18 digits precision.&lt;BR /&gt;
&lt;BR /&gt;
on z/OS, see&lt;BR /&gt;
&lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/hosto390.hlp/mvs-length-length.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/hosto390.hlp/mvs-length-length.htm&lt;/A&gt;&lt;BR /&gt;
There it declares 16 digits &lt;BR /&gt;
&lt;BR /&gt;
On windows the corresponding table is different because the the storage form is different. The result is that the table at &lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/hostwin.hlp/numvar.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/hostwin.hlp/numvar.htm&lt;/A&gt; offers only to retain precision for 15 digits.&lt;BR /&gt;
&lt;BR /&gt;
As SAS on unix uses the same internal storage as on windows, it is no surprise that the limitations are declared the same, in the table at &lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/hostunx.hlp/a000344718.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/hostunx.hlp/a000344718.htm&lt;/A&gt; .&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
So, if you want to rely on 18 digits precision, either hold it as 18 characters, 9 bytes of unsigned packed numeric, or some extremely clever binary combination.&lt;BR /&gt;
&lt;BR /&gt;
Certainly do not rely on retrieving any 18 digits you store in a SAS numeric variable. Of course, you may be lucky !&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Good Luck&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 05 Feb 2008 16:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Padding-a-field-with-0/m-p/6758#M2173</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-05T16:09:01Z</dc:date>
    </item>
  </channel>
</rss>

