Page 1 of 1

Can we append a constant number to records after an interval?

Posted: Tue May 17, 2016 3:20 pm
by Biden
Hi,

For a Fixed-block file, if I need to append two different constant number to records, at the end; can I do that? For example, if my input file has say 20K records. Can I append a constant number of two digits at the end of every 7th and 10th records. I also want to count them, is it possible? If yes, can you please help me.

Re: Can we append a constant number to records after an interval?

Posted: Tue May 17, 2016 8:22 pm
by Robert Sample
If yes, can you please help me.
The simplest way would be to write a program in the language of your choice to count the records and output the appropriate constants.  If your site has SAS, such a program would easily be coded, tested, and executed in half a day or less by any competent SAS programmer.
You can probably do this with the sort product in use at your site, but you need to provide more information before anyone on this (or any) forum could help you.  For example, you didn't say if you want to add 2 bytes to the record length or if there are blanks at the end of the record you want to replace with your constants.  You didn't say what happens every 70th record when the 7th and 10th records are the same -- append the 7 value? append the 10 value? append both values and add 4 bytes instead of 2 bytes?  We would also need to know which sort product your site uses.

Re: Can we append a constant number to records after an interval?

Posted: Thu May 19, 2016 1:40 pm
by Biden
We are using DFSORT. I would like to add 2 bytes to the record length. I did not think about 70th record while posting but appending both values, 4 bytes, will be fine.

Re: Can we append a constant number to records after an interval?

Posted: Fri May 20, 2016 2:16 am
by Robert Sample
If you add 2 bytes every 7th and 10th records, and 4 bytes every 70th record, you are no longer talking about fixed-length records.
You can use IFTHEN and OUTREC in DFSORT to generate a sequence number and check for appropriate values to add your bytes.  It would be worth considering writing a short program in the language of your choice to do this, though, since getting DFSORT processing correct can take as long or longer than coding.  A SAS program for this would be less than a screen of code, based on what you've said so far.  Part of becoming an experienced programmer is learning when to use the utilities available and when to write code.

Re: Can we append a constant number to records after an interval?

Posted: Fri May 20, 2016 11:58 am
by William Collins
Yes, it can be done, a little faster than Robert is alluding :-)

What do you want to put in those two bytes?

Do you want separate counts, or a count of records changed? Actually, separate counts are easy (divide total number of records by seven for the first and 10 for the second). There's even a formula to calculate how many there are "net" (only counting a seven-and-10 as one). Something to do with "triangular"? Robert will probably know much better than I.

Re: Can we append a constant number to records after an interval?

Posted: Fri May 20, 2016 3:09 pm
by Biden
William Collins wrote:Yes, it can be done, a little faster than Robert is alluding :-)

What do you want to put in those two bytes?

Do you want separate counts, or a count of records changed? Actually, separate counts are easy (divide total number of records by seven for the first and 10 for the second). There's even a formula to calculate how many there are "net" (only counting a seven-and-10 as one). Something to do with "triangular"? Robert will probably know much better than I.
I want to add numbers as of now.
Separate counts is fine. By 'triangular' what do you mean?