DATA Step, Macro, Functions and more

INFILE in JCL

Reply
New Contributor
Posts: 2

INFILE in JCL

[ Edited ]

I have to write a file using 2 input files.

INFILE IPADFILE;
INPUT @001 BEGIN_REC $CHAR30.
@031 NAME $CHAR5.
@036 MIDDLE_REC $CHAR86.
@122R_SYS $CHAR1.
@123END_REC $CHAR22.
INFILE IXREF;
INPUT @001 LOCN $CHAR5.
@006 K_LOCN $CHAR5.
@011 END_RECRD $CHAR68.;

 

Now I have to write output which will have same structure same as IPADFILE but while writing it i want to replace  @031 NAME $CHAR5 from @006 K_LOCN $CHAR5, basically i want output file as per below structure:

 

PUT @001 BEGIN_REC $CHAR30.
@031 K_LOCN $CHAR5.
@036 MIDDLE_REC $CHAR86.
@122R_SYS $CHAR1.
@123END_REC $CHAR22.;

 

IPADFILE and IXREF are DD name of the files in JCL.

 

Can anyone please help.

Super User
Posts: 6,628

Re: INFILE in JCL

An idea or two first ...

 

You are overcomplicating things by reading in all the variables.  For example, if you need just K_LOCN, read just K_LOCN:

 

INFILE IXREF;

INPUT @006 K_LOCN $CHAR5.;

 

Are  you sure these files match up line by line?  So far, you are asking to match the first line of 1 file with the first line from the other file, then the 2nd line of 1 file with the 2nd line from the other file, etc.

 

Where should the output go?  Do you want to replace the IPADFILE?  Write to a new file?  Write a report?

 

If you want to write to a new file, you need JCL to define that new file.

 

There's more to consider, but that's a good starting point.

New Contributor
Posts: 2

Re: INFILE in JCL

Posted in reply to Astounding

Thanks for comment.

I need to write the output in a new file and that is defined in JCL.
The structure of first inputfile (IPADFILE) and output file is identical,
while writting the output file i need all the fields from IPADFILE except the @031 NAME $CHAR5 , i want it to be replaced by the IXREF file's @006 K_LOCN $CHAR5.

Super User
Posts: 6,628

Re: INFILE in JCL

OK, for that you don't need to read all the fields from IPADFILE.  Here's a neat trick:

 

INFILE IPADFILE;

INPUT DUMMY $ 1. @ ;

FILE NEWFILE;

PUT _INFILE_ @ ;

INFILE IXREF;

INPUT @ 6 K_LOCN $CHAR5.;

PUT @ 6 K_LOCN $CHAR5.;

 

Test it to make sure the information matches up properly line by line.

 

_INFILE_ refers to an exact copy of the most recent raw data line, so you don't need to break it into pieces.  Just write out the whole thing, then overwrite 5 characters of that with the contents of K_LOCN.

Super User
Super User
Posts: 7,932

Re: INFILE in JCL

[ Edited ]

You don't have to type your SAS code in uppercase (its not JCL).

If you know the records are in the same order then you should be able to just overwrite the characters starting at column 31 with the string from the record in the other file.

// EXEC SAS
//IPADFILE DD ...
//IXREF DD ...
//NEWFILE DD ...
//SYSIN DD *
data _null_;
  file newfile ;
  infile ipadfile;
  input ;
  put _infile_ @ ;
  infile ixref;
  input @6 string $char5.;
  put @31 string $char5.;
run;

 If you really want the file to look exactly the same you might need to specify the file attributes (RECFM, LRECL, etc) for the output file in the JCL.  Isn't there a way in JCL to copy the attributes from another file? Or perhaps you could set them in the FILE statement of the SAS code.

 

Ask a Question
Discussion stats
  • 4 replies
  • 158 views
  • 0 likes
  • 3 in conversation