I tried using Splice but it does not allow duplicates.
It's not clear from your example what you want to do or what you mean by "Splice does not allow duplicates". SPLICE can do one-to-many with the WITHALL parameter if that's what you mean by "duplicates".
But I don't see any pattern in your output records, so I can't tell you how to do what you want to do. The 1's have an X in the first record, whereas the 2's have a Y in the first two records, and the rest of the records don't have an X at all. Where's the pattern there? How is anybody supposed to figure out from that example what you want? We can't read your mind. Please explain the "rules" for getting from the input records to the output records. What exactly are you trying to do?