<?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 blanks in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/leading-blanks/m-p/32481#M7825</link>
    <description>Hi:&lt;BR /&gt;
  Partly the answer depends on what you want to do with ID and whether ID is character or numeric. If ID is numeric, then SAS will not -store- leading zeroes -- however, you can -display- leading zeroes by simply using a FORMAT statement (probably best in this case to permanently associate a format with the ID variable).&lt;BR /&gt;
[pre]format ID z5.;&lt;BR /&gt;
   [/pre]&lt;BR /&gt;
                                                          &lt;BR /&gt;
If you put that format statement in the program where you read the text file (assuming you're using a DATA step program), then SAS would format the ID to be 5 digits, with leading zeroes. So the internally stored number '123' would display on all reports as '00123', for example. If you are importing the data without a DATA step, then you can always modify the format attribute with PROC DATASETS, after the dataset is created.&lt;BR /&gt;
 &lt;BR /&gt;
However, if you read ID as a character variable and then store it as a character variable, SAS will both -store- and -display- the leading zeroes without needing a user defined format.  &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data leadzero;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input name $ as_num_id as_char_id $;&lt;BR /&gt;
  format as_num_id z5.;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
alan 00123 00123&lt;BR /&gt;
bob 00234  00234&lt;BR /&gt;
cathy 00345 00345&lt;BR /&gt;
dana 00456 00456&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                           &lt;BR /&gt;
proc print data=leadzero;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Fri, 15 May 2009 15:01:53 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-05-15T15:01:53Z</dc:date>
    <item>
      <title>leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/leading-blanks/m-p/32480#M7824</link>
      <description>I am importing a txt file to sas.  the ID field has leading zeros which i wish to retain.  after importing i find that the zeros are not being imported.  how can I imported the data while retaining the zeros.  &lt;BR /&gt;
&lt;BR /&gt;
thanks</description>
      <pubDate>Fri, 15 May 2009 13:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/leading-blanks/m-p/32480#M7824</guid>
      <dc:creator>Hart</dc:creator>
      <dc:date>2009-05-15T13:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/leading-blanks/m-p/32481#M7825</link>
      <description>Hi:&lt;BR /&gt;
  Partly the answer depends on what you want to do with ID and whether ID is character or numeric. If ID is numeric, then SAS will not -store- leading zeroes -- however, you can -display- leading zeroes by simply using a FORMAT statement (probably best in this case to permanently associate a format with the ID variable).&lt;BR /&gt;
[pre]format ID z5.;&lt;BR /&gt;
   [/pre]&lt;BR /&gt;
                                                          &lt;BR /&gt;
If you put that format statement in the program where you read the text file (assuming you're using a DATA step program), then SAS would format the ID to be 5 digits, with leading zeroes. So the internally stored number '123' would display on all reports as '00123', for example. If you are importing the data without a DATA step, then you can always modify the format attribute with PROC DATASETS, after the dataset is created.&lt;BR /&gt;
 &lt;BR /&gt;
However, if you read ID as a character variable and then store it as a character variable, SAS will both -store- and -display- the leading zeroes without needing a user defined format.  &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data leadzero;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input name $ as_num_id as_char_id $;&lt;BR /&gt;
  format as_num_id z5.;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
alan 00123 00123&lt;BR /&gt;
bob 00234  00234&lt;BR /&gt;
cathy 00345 00345&lt;BR /&gt;
dana 00456 00456&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                           &lt;BR /&gt;
proc print data=leadzero;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 15 May 2009 15:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/leading-blanks/m-p/32481#M7825</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-05-15T15:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: leading blanks</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/leading-blanks/m-p/32482#M7826</link>
      <description>thanks format z7. did the trick</description>
      <pubDate>Fri, 15 May 2009 18:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/leading-blanks/m-p/32482#M7826</guid>
      <dc:creator>Hart</dc:creator>
      <dc:date>2009-05-15T18:56:15Z</dc:date>
    </item>
  </channel>
</rss>

