BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mmd575
Calcite | Level 5

Hello,

I am in the process of sending out a fixed width .txt attachment I have an issue every time I try to send the fixed width text document as an attachment through SAS e-mail, the text is all over the place and the format is ruined. Any tips on how to correct this? Thank you in advance for your response! I have the code below (I did alias a lot of my code particularly for the e-mail and file paths, since this code is for my company):

DATA _NULL_;

    FILE "/DialerFile_&Yesterday..txt" LRECL=623 PAD termstr=crlf;

    SET outlib.final_daily_assignment;

    Spaces = " ";

    PUT

        @01 DataDate

  @11 " "

  @12 " "

  @20 Account

  @43 " "

  @45 " "

  @47 Agent

  @55 " "

  @57 " "

  @65 DPD ;

RUN;

filename mymail email 'me@gmail.COM'

  attach=("/DialerFile_&Yesterday..txt" LRECL=32767)

  content_type="text/plain"

     subject="Dialer File";

           

data _null_;

  file mymail

  to=("me@gmail.COM")

      subject="Dialer File"

   CONTENT_TYPE="text/plain";

  put 'Hi,';

  put "                         ";

  put "The Dialer File for &Yesterday is attached.";

  put ",                     ";

  put "SAS                    ";

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You could simplify your data step that is generating the text file.

Remove the PAD option as that does not appear to be needed from your example.

Make sure the LRECL you specify is large enough to prevent SAS from "wrapping" around to the next line.  That is don't try to write 100 characters starting at column 600 if your lrecl is less than 700.

There is no need to write spaces as the column pointer movement commands will put the information in the right place.

You might want to add formats in your PUT statement for some of the fields, particularly if the format you want to write them is not the format that permanently attached to the variable in the input dataset.  For example you might have DataDate formatted as DATE9. in the FINAL_DAILY_ASSIGNMENT dataset by want to write it as YYMMDDN8. in the generated text file.

DATA _NULL_;

  FILE "/DialerFile_&Yesterday..txt" LRECL=623 termstr=crlf;

  SET outlib.final_daily_assignment;

  PUT      

  @01 DataDate

  @20 Account

  @47 Agent

  @65 DPD

  ;

RUN;

View solution in original post

8 REPLIES 8
ballardw
Super User

You might provide an example of "ruined format" and intended format.

If someone is reading the document using a proportional font, as almost every application except Notepad and programing editors do, then multiple spaces will appear as different widths and column alignment goes out the window.

Also, if your Dialer.txt file looks good before you send it it may be the recipient's email program doing something with attachments.

mmd575
Calcite | Level 5

I updated my post to include the attachments. The first txt attachment is what the file looks like when I use proc export and it is saved onto our server. The second file is the result of what the attachment ends up looking like after I send it through with the SAS e-mail code that I provided above. I am using Outlook for this, and the result I attached I had to change numbers since there are account numbers in my data which I cannot post on here. However, I am testing the program by sending these attachments to myself and the receiver of my file will have the same Operating System/E-mail program as myself. It appears as that my SAS code doesn't recognize new lines in the .txt file?

Tom
Super User Tom
Super User

It is not clear from your description which of these two files you consider to be correct.

Data doesn't look misaligned to me, just that one of the files doesn't have all of the spaces padded onto the file. 

What makes you think it is misaligned?

Why do you use the PAD option on your FILE statement?  Who do you need to include the extra spaces on the end of the lines?

157  data _null_;

158    infile 'c:\downloads\examplesas.txt' obs=3 lrecl=50000;

159    input;

160    list;

161  run;

NOTE: The infile 'c:\downloads\examplesas.txt' is:

      Filename=c:\downloads\examplesas.txt,

      RECFM=V,LRECL=50000,File Size (bytes)=1025,

      Last Modified=31May2013:17:20:36,

      Create Time=31May2013:17:20:36

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-

1         2013-05-31         1000000000                 ID100000          35

      87

     173

     259

     345

     431

     517

     603                       = 624

2         2013-05-31         1000000000                 ID100000          89

      87

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-

     173

     259

     345                                                           400

NOTE: 2 records were read from the infile 'c:\downloads\examplesas.txt'.

      The minimum record length was 400.

      The maximum record length was 624.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.00 seconds

162

163  data _null_;

164    infile 'c:\downloads\example.txt' obs=3 lrecl=50000;

165    input;

166    list;

167  run;

NOTE: The infile 'c:\downloads\example.txt' is:

      Filename=c:\downloads\example.txt,

      RECFM=V,LRECL=50000,File Size (bytes)=848,

      Last Modified=31May2013:17:20:36,

      Create Time=31May2013:17:20:36

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-

1         2013-05-31         1000000000                 ID500000          35 66

2         2013-05-31         1000000000                 ID500000          35 66

3         2013-05-31         1000000000                 ID500000          35       72

NOTE: 3 records were read from the infile 'c:\downloads\example.txt'.

      The minimum record length was 66.

      The maximum record length was 72.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

mmd575
Calcite | Level 5

Sorry Tom, I wanted my output to look like the Example.txt file. I had the pad statement there by default as this was how the code was given to me, it was my understanding it would help write out the data correctly? Is this an unnecessary step?

Tom
Super User Tom
Super User

You could simplify your data step that is generating the text file.

Remove the PAD option as that does not appear to be needed from your example.

Make sure the LRECL you specify is large enough to prevent SAS from "wrapping" around to the next line.  That is don't try to write 100 characters starting at column 600 if your lrecl is less than 700.

There is no need to write spaces as the column pointer movement commands will put the information in the right place.

You might want to add formats in your PUT statement for some of the fields, particularly if the format you want to write them is not the format that permanently attached to the variable in the input dataset.  For example you might have DataDate formatted as DATE9. in the FINAL_DAILY_ASSIGNMENT dataset by want to write it as YYMMDDN8. in the generated text file.

DATA _NULL_;

  FILE "/DialerFile_&Yesterday..txt" LRECL=623 termstr=crlf;

  SET outlib.final_daily_assignment;

  PUT      

  @01 DataDate

  @20 Account

  @47 Agent

  @65 DPD

  ;

RUN;

mmd575
Calcite | Level 5

Thank you so much Tom. I removed the pad, and kept the code simple and it works perfectly. I appreciate you taking the time to reply to my post.

mmd575
Calcite | Level 5

I also forgot to mention that I only gave a snippet of the second attachment, it actually has more and more repeating lines of data that is misaligned.

Tom
Super User Tom
Super User

I have also had Outlook "help" me by removing the end of lines from ASCII messages.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1753 views
  • 0 likes
  • 3 in conversation