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;

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
  • 5 replies
  • 963 views
  • 2 likes
  • 4 in conversation