Hello, I am a novice sas user. I recently have found a solution to my problem, but figuring out why it is working has been diffiicult. It is crucial that I understand whats going on. It is my hope that someone can explain why this code is effective. Basically, I have three distinct Keys (incident_key, discipline_key, and offender_key) and want to concatenate by row to include all offense codes in one line. A mock version of the data, called "discipline" looks like: incident_id discipline_key offender_key offense_code 1 11 9011 FA 1 12 2867 FA 2 345 666 FA 2 345 666 WR 2 678 8975 YP 2 678 8975 RQ I found this solution on this same website, and it works perfectly: data discipline_with_concat; length all_offense $200.; do until (last.discipline_key); set discipline; by discipline_key notsorted; all_offense=catx(',',all_offense,number); end; The code provides this output: incident_id discipline_key offender_key offense_code all_offense 1 11 9011 FA FA 1 12 2867 FA FA 2 345 666 FA FA,WR 2 678 8975 YP YP,RQ Can someone please explain, if possible, in a simple and linear way, how this code is working? Often to find answers I run variations of the code and that made me wonder: Why is it that I need to concatenate offense_code with the newly created variable specified in the length statement? If i do not do that, it simply pulls the last observation for each discipline key. Any insight would be greatly appreciated, thanks!
... View more