I can give you a little guidance, but I can't solve it. I'm having trouble seeing how the output you post matches your description of what you want to achieve. Regardless of what is needed, however, this looks like a case where the problem would become easier if you were to transpose the data. Picture one observation per ID, with variables StartDate1 through StartDate20 and Drug1 through Drug20. (Of course, 20 is an arbitrary number ... you need to create enough variables to hold the data for the patient with the largest number of dates.)
While I rarely recommend transposing data into that form, this strikes me as a problem that would become easier if you were to do that.
Good luck.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.