Well done, taking it this far. Just in case there are still any issues, here a few comments. One of the PROC SORTs can come out: PROC SORT DATA=mydata; BY CID PRODUCT ID; RUN; The data had already been sorted, and they remain in order. So the second PROC SORT isn't needed (check the log ... SAS probably figured out it should skip this second sort). If there is still an issue with the PRODUCT values, the suspect is here: PRODUCT = "&&PRODUCT&I"; That would be the correct syntax if you had already split &OBSERVATIONS into separate macro variables named &PRODUCT1, &PRODUCT2, ... &PRODUCTn. Here, all you really need is the same syntax that worked in the %PUT statement: PRODUCT = "%SCAN(&OBSERVATIONS,&I)"; You may have already tackled that, so this is in the spirit of "just in case it helps".
... View more