I think you can use a combination of BY group processing and the LAG function to get the results you want.
proc sort data=one; by number; run;
data two; set one; by number; y=lag(code); if first.number then y=.; run;
The 2025 SAS Hackathon Kicks Off on June 11!
Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.