<?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: Writing SAS data to a text file in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5669#M1801</link>
    <description>Hi: &lt;BR /&gt;
&lt;BR /&gt;
When you use any of the SAS formats to write your date variables, SAS does put leading 0s on dates like 01/01/1960. However, even if you get the leading 0s in your ASCII text file, the application (like Excel) that is going to open the ASCII file may turn around and strip out the leading 0s -- so you have to check whether your leading 0s will be respected by the application that's going to open your file.&lt;BR /&gt;
&lt;BR /&gt;
So, what if this is what your data (WORK.DATETEST) looks like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs    name     date1     date2     date3     date4&lt;BR /&gt;
&lt;BR /&gt;
 1     alan     -3334     -3334     -3334     -3334&lt;BR /&gt;
 2     bob      16927     16927     16927     16927&lt;BR /&gt;
 3     carl         0         0         0         0&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
(Alan's date is 11/15/1950; Bob's date is 05/06/2006; and Carl's date is 01/01/1960) What you see in the above file is the internally stored SAS date value as the number of days since Jan 1, 1960. If I run this code:&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
ods csv(1) file='c:\temp\OpenWithExcel.csv';&lt;BR /&gt;
ods csv(2) file='c:\temp\OpenWithNotepad.txt';&lt;BR /&gt;
proc print data=work.datetest split='*';&lt;BR /&gt;
  var date1 date2 date3 date4;&lt;BR /&gt;
  format date2 mmddyy10.&lt;BR /&gt;
         date3 date9.&lt;BR /&gt;
         date4 date7.;&lt;BR /&gt;
  label date1='SAS Internal* Date Value'&lt;BR /&gt;
        date2='mmddyy10.* Standard Format'&lt;BR /&gt;
        date3='date9.* Standard Format'&lt;BR /&gt;
        date4='date7.* Standard Format';&lt;BR /&gt;
run;&lt;BR /&gt;
ods _all_ close;&lt;BR /&gt;
    &lt;BR /&gt;
** Even if you create an ASCII file with PUT statement;&lt;BR /&gt;
** some software programs may still suppress the leading zeros;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set work.datetest;&lt;BR /&gt;
file 'c:\temp\date_ascii.txt'; &lt;BR /&gt;
put @1 name  @7 date1 date9. @19 date2 mmddyy10. ;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
 When I open either of the .TXT files with Notepad, I see that SAS did put leading 0s in the ASCII CSV file. &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
"Obs","SAS Internal Date Value","mmddyy10. Standard Format","date9. Standard Format","date7. Standard Format"&lt;BR /&gt;
"1",-3334,"11/15/1950","15NOV1950","15NOV50"&lt;BR /&gt;
"2",16927,"05/06/2006","06MAY2006","06MAY06"&lt;BR /&gt;
"3",0,"01/01/1960","01JAN1960","01JAN60"&lt;BR /&gt;
[/pre]&lt;BR /&gt;
AND in the DATE_ASCII.TXT file&lt;BR /&gt;
[pre]&lt;BR /&gt;
alan  15NOV1950   11/15/1950&lt;BR /&gt;
bob   06MAY2006   05/06/2006&lt;BR /&gt;
carl  01JAN1960   01/01/1960&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
But, if you open either of the files with Excel, you will see that Excel does not respect the SAS formats and strips out the leading 0s.&lt;BR /&gt;
 &lt;BR /&gt;
So, you're right -- it is a basic question -- and the answer is to use either a SAS format or a user-defined format to preserve the leading 0s in your ASCII text file. Are you using SAS formats to write your data out to the ASCII text file? If what is happening AFTER the ASCII text file is opened (possibly with Excel) is what you're trying to work-around, then, that's a different question. &lt;BR /&gt;
&lt;BR /&gt;
Can you elaborate on how you're using the date and why you think that leading 0s are NOT being preserved?&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Mon, 26 Nov 2007 20:03:33 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2007-11-26T20:03:33Z</dc:date>
    <item>
      <title>Writing SAS data to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5668#M1800</link>
      <description>This is a basic question but I can't seem to find the answer to it.&lt;BR /&gt;
&lt;BR /&gt;
I need to write out a date (that is, unfortunately, numeric rather than a SAS date) to an ASCII file. I would like to preserve any leading 0s. Currently I have a data step that converts the numeric date to character to accomplish this. &lt;BR /&gt;
&lt;BR /&gt;
Is there a more efficient way to do this where I can skip the data step?</description>
      <pubDate>Mon, 26 Nov 2007 15:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5668#M1800</guid>
      <dc:creator>npa</dc:creator>
      <dc:date>2007-11-26T15:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Writing SAS data to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5669#M1801</link>
      <description>Hi: &lt;BR /&gt;
&lt;BR /&gt;
When you use any of the SAS formats to write your date variables, SAS does put leading 0s on dates like 01/01/1960. However, even if you get the leading 0s in your ASCII text file, the application (like Excel) that is going to open the ASCII file may turn around and strip out the leading 0s -- so you have to check whether your leading 0s will be respected by the application that's going to open your file.&lt;BR /&gt;
&lt;BR /&gt;
So, what if this is what your data (WORK.DATETEST) looks like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs    name     date1     date2     date3     date4&lt;BR /&gt;
&lt;BR /&gt;
 1     alan     -3334     -3334     -3334     -3334&lt;BR /&gt;
 2     bob      16927     16927     16927     16927&lt;BR /&gt;
 3     carl         0         0         0         0&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
(Alan's date is 11/15/1950; Bob's date is 05/06/2006; and Carl's date is 01/01/1960) What you see in the above file is the internally stored SAS date value as the number of days since Jan 1, 1960. If I run this code:&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
ods csv(1) file='c:\temp\OpenWithExcel.csv';&lt;BR /&gt;
ods csv(2) file='c:\temp\OpenWithNotepad.txt';&lt;BR /&gt;
proc print data=work.datetest split='*';&lt;BR /&gt;
  var date1 date2 date3 date4;&lt;BR /&gt;
  format date2 mmddyy10.&lt;BR /&gt;
         date3 date9.&lt;BR /&gt;
         date4 date7.;&lt;BR /&gt;
  label date1='SAS Internal* Date Value'&lt;BR /&gt;
        date2='mmddyy10.* Standard Format'&lt;BR /&gt;
        date3='date9.* Standard Format'&lt;BR /&gt;
        date4='date7.* Standard Format';&lt;BR /&gt;
run;&lt;BR /&gt;
ods _all_ close;&lt;BR /&gt;
    &lt;BR /&gt;
** Even if you create an ASCII file with PUT statement;&lt;BR /&gt;
** some software programs may still suppress the leading zeros;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set work.datetest;&lt;BR /&gt;
file 'c:\temp\date_ascii.txt'; &lt;BR /&gt;
put @1 name  @7 date1 date9. @19 date2 mmddyy10. ;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
 When I open either of the .TXT files with Notepad, I see that SAS did put leading 0s in the ASCII CSV file. &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
"Obs","SAS Internal Date Value","mmddyy10. Standard Format","date9. Standard Format","date7. Standard Format"&lt;BR /&gt;
"1",-3334,"11/15/1950","15NOV1950","15NOV50"&lt;BR /&gt;
"2",16927,"05/06/2006","06MAY2006","06MAY06"&lt;BR /&gt;
"3",0,"01/01/1960","01JAN1960","01JAN60"&lt;BR /&gt;
[/pre]&lt;BR /&gt;
AND in the DATE_ASCII.TXT file&lt;BR /&gt;
[pre]&lt;BR /&gt;
alan  15NOV1950   11/15/1950&lt;BR /&gt;
bob   06MAY2006   05/06/2006&lt;BR /&gt;
carl  01JAN1960   01/01/1960&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
But, if you open either of the files with Excel, you will see that Excel does not respect the SAS formats and strips out the leading 0s.&lt;BR /&gt;
 &lt;BR /&gt;
So, you're right -- it is a basic question -- and the answer is to use either a SAS format or a user-defined format to preserve the leading 0s in your ASCII text file. Are you using SAS formats to write your data out to the ASCII text file? If what is happening AFTER the ASCII text file is opened (possibly with Excel) is what you're trying to work-around, then, that's a different question. &lt;BR /&gt;
&lt;BR /&gt;
Can you elaborate on how you're using the date and why you think that leading 0s are NOT being preserved?&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 26 Nov 2007 20:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5669#M1801</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-26T20:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Writing SAS data to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5670#M1802</link>
      <description>Hi Npa.&lt;BR /&gt;
I understand your date problem slightly differently from Cynthia. To me it seems that you have a variable which values are something like 990512 or 71111 to store dates like may 12th, 1999 or november 11th, 2007. And you'd like to store them as 990512 and 071111 in your text file.&lt;BR /&gt;
The trick is exactly what Cynthia offered, using ODS CSV and specifying formats in a Print Procedure. In this case, the format would be something like Z6. to display leading zeroes if any.&lt;BR /&gt;
If you want to use Proc Export, you cannot escape a preliminary Proc Sort ou Data step to associate Z6. format to your variables permanently ; if you specify a format in a proc Export, it is simply ignored.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Olivier.</description>
      <pubDate>Tue, 27 Nov 2007 13:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5670#M1802</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2007-11-27T13:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Writing SAS data to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5671#M1803</link>
      <description>What Cynthia has said is correct. The leading zeroes are preserved. I do have a followup question. Does SAS have a date format that would write out the observations as follows (numbers only):&lt;BR /&gt;
&lt;BR /&gt;
Obs         Name           Date&lt;BR /&gt;
1           John             07102007       (July 10, 2007)&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: npa

Message was edited by: npa</description>
      <pubDate>Tue, 27 Nov 2007 15:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5671#M1803</guid>
      <dc:creator>npa</dc:creator>
      <dc:date>2007-11-27T15:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Writing SAS data to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5672#M1804</link>
      <description>Hi:&lt;BR /&gt;
  Yes, you can specify a separator character for a variant of the MMDDYY format. If you check out the documentation, these are the separators:&lt;BR /&gt;
&lt;BR /&gt;
B separates with a blank&lt;BR /&gt;
C separates with a colon&lt;BR /&gt;
D separates with a dash &lt;BR /&gt;
N indicates no separator&lt;BR /&gt;
P separates with a period &lt;BR /&gt;
S separates with a slash.&lt;BR /&gt;
&lt;BR /&gt;
and here's a program that shows using the N separator (in the PROC PRINT):&lt;BR /&gt;
[pre]&lt;BR /&gt;
data bday;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input name $ bday : mmddyy10.;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
alan 11/15/1950&lt;BR /&gt;
bob 06/30/1949&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
proc print data=bday;&lt;BR /&gt;
format bday mmddyyn8.;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 27 Nov 2007 15:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5672#M1804</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-27T15:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Writing SAS data to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5673#M1805</link>
      <description>Thanks, Cynthia!!</description>
      <pubDate>Tue, 27 Nov 2007 16:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Writing-SAS-data-to-a-text-file/m-p/5673#M1805</guid>
      <dc:creator>npa</dc:creator>
      <dc:date>2007-11-27T16:16:38Z</dc:date>
    </item>
  </channel>
</rss>

