08-28-2017 02:25 PM - edited 08-28-2017 02:28 PM
I have to write a file using 2 input files.
INPUT @001 BEGIN_REC $CHAR30.
@031 NAME $CHAR5.
@036 MIDDLE_REC $CHAR86.
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:
IPADFILE and IXREF are DD name of the files in JCL.
Can anyone please help.
08-28-2017 02:40 PM
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:
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.
08-28-2017 02:53 PM
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.
08-28-2017 03:03 PM
OK, for that you don't need to read all the fields from IPADFILE. Here's a neat trick:
INPUT DUMMY $ 1. @ ;
PUT _INFILE_ @ ;
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.
08-28-2017 11:45 PM - edited 08-28-2017 11:47 PM
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.