Help using Base SAS procedures

Specify carriage return in specific position

Accepted Solution Solved
Reply
Contributor
Posts: 61
Accepted Solution

Specify carriage return in specific position

Hello-

I have the following code and need to place a carriage return at a specific position in a text file.  The start position of the carriage return/CRLF must be at 325.  Can anyone help me?

DATA _NULL_;

file 'I:\ENCTv1.TXT' LRECL= 325;

   IF _N_ = 1 THEN DO;

   SET LEVEL_HDR;

   PUT

@1  FILE_TYPE

@51 TOTAL_RECORDS_IN_FILE

@61 FILE_NAME

@86 FILE_ID

@118 FILE_RPT_PERIOD;

END;

SET LEVEL_body;  

PUT @1 RECORD_NUM @11 ZIP @13 AGG_NUM @15 AGG_ID  @49 TABLE_NAME @69 GRADE

    @84 RESI @114 TOTAL_INDICATOR  @315 COUNT;

RUN;


Accepted Solutions
Solution
‎12-11-2012 03:10 PM
Respected Advisor
Posts: 3,156

Re: Specify carriage return in specific position

Posted in reply to Suzanne_Ed

DATA _NULL_;

file 'I:\ENCTv1.TXT' LRECL= 325;

  IF _N_ = 1 THEN DO;

  SET LEVEL_HDR;

  PUT

@1 FILE_TYPE

@51 TOTAL_RECORDS_IN_FILE

@61 FILE_NAME

@86 FILE_ID

@118 FILE_RPT_PERIOD;

END;

SET LEVEL_body;

PUT @1 RECORD_NUM @11 ZIP @13 AGG_NUM @15 AGG_ID @49 TABLE_NAME @69 GRADE

  @84 RESI @114 TOTAL_INDICATOR @315 COUNT @325 '0D'x;

RUN;

Haikuo

View solution in original post


All Replies
Respected Advisor
Posts: 3,799

Re: Specify carriage return in specific position

Posted in reply to Suzanne_Ed

Add the FILE statement option PAD.

data _null_;
  
file '~/exp.txt' dsd pad lrecl=75;
  
set sashelp.class;
   put (_all_)(=);
   run;
data _null_;
  
infile '~/exp.txt';
  
input;
  
list;
  
run;
Respected Advisor
Posts: 3,156

Re: Specify carriage return in specific position

Posted in reply to data_null__

Liked!

Solution
‎12-11-2012 03:10 PM
Respected Advisor
Posts: 3,156

Re: Specify carriage return in specific position

Posted in reply to Suzanne_Ed

DATA _NULL_;

file 'I:\ENCTv1.TXT' LRECL= 325;

  IF _N_ = 1 THEN DO;

  SET LEVEL_HDR;

  PUT

@1 FILE_TYPE

@51 TOTAL_RECORDS_IN_FILE

@61 FILE_NAME

@86 FILE_ID

@118 FILE_RPT_PERIOD;

END;

SET LEVEL_body;

PUT @1 RECORD_NUM @11 ZIP @13 AGG_NUM @15 AGG_ID @49 TABLE_NAME @69 GRADE

  @84 RESI @114 TOTAL_INDICATOR @315 COUNT @325 '0D'x;

RUN;

Haikuo

Contributor
Posts: 61

Re: Specify carriage return in specific position

Awesome!  Placed the carriage return at 325- but now I have a blank row record after every data record??

Super User
Posts: 10,041

Re: Specify carriage return in specific position

Posted in reply to Suzanne_Ed

Why not use :

file '~/exp.txt' dsd pad lrecl=75 termstr=CRLF;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 306 views
  • 2 likes
  • 4 in conversation