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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

5 REPLIES 5
data_null__
Jade | Level 19

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;
Haikuo
Onyx | Level 15

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

SannaSanna
Quartz | Level 8

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

Ksharp
Super User

Why not use :

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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