Page 1 of 1
Copy only the last record from input to output.
Posted: Thu Oct 01, 2015 9:59 am
by Ameya C
Hi,
I have a VBS file from which I need to get the first record and last record in the output file. I used STOPAFT=1 but it helps to get the first record. But I am not sure how to get the last record only.
Can you please tell me how to get only the last record from a VBS file using SORT.
Thanks,
Re: Copy only the last record from input to output.
Posted: Thu Oct 01, 2015 11:48 am
by William Collins
Use JOINKEYS with the same dataset. JOIN UNPAIRED,F1,F2,ONLY. REFORMAT statement including the entire F1 and F2 and the match-markers (?). Depending on value of match-marker, BUILD correct output.The key for the JOINKEYS is an extension to the record containing a sequence number (large enough to be unique for each record in the file). This will be set in the JNFnCNTL files. For one sequence number use START=0, for the other use START=1.
Re: Copy only the last record from input to output.
Posted: Thu Oct 01, 2015 11:52 am
by William Collins
Or, for less code and excitement, look at ICETOOL's SUBSET operator.
Re: Copy only the last record from input to output.
Posted: Thu Oct 01, 2015 4:52 pm
by zprogrammer
Or even OUTFIL NODETAIL with TRAILER

Re: Copy only the last record from input to output.
Posted: Thu Oct 01, 2015 6:59 pm
by William Collins
Yes, like this:
Code: Select all
OUTFIL HEADER1=(1,80),
TRAILER1=(1,80),
REMOVECC,
NODETAIL
The other two are more flexible, as different numbers of "first" and "last" records could be processed (or ignored).
Re: Copy only the last record from input to output.
Posted: Thu Oct 01, 2015 7:02 pm
by zprogrammer
Ok Thanks William
