Hi, first time poster here. I am just starting to use SAS after a couple long layoffs, so am more than a bit rusty. I'm using SAS 9.4 for Windows. Anyhow, I'm trying to rollup some data that into one row per ID/question. My data looks like this: ID Q Answer 1 1 None 1 2 Read Aloud 1 3 Distract 1 4 Overall 2 1 Single 2 2 Sign 2 2 PAS 2 3 None 2 4 Behavior 3 1 Two choice 3 2 Sign 3 3 Too high 3 4 Overall 3 4 Behavior 3 4 Environment I want it to look like this: ID Q Answer 1 1 None 1 2 Read Aloud 1 3 Distract 1 4 Overall 2 1 Single 2 2 Sign, PAS 2 3 None 2 4 Behavior 3 1 Two choice 3 2 Sign 3 3 Too High 3 4 Overall, Behavior, Environment My code looks like this: data want;
set have (rename=(answer=answer1));
by id q;
length answer $250; *there are up to 6 answers that can be combined here;
retain answer
if first.id and first.q then answer=' ';
answer=catx(',',answer, answer1);
if last.q then output;
run; It's giving me all the combined answers in last.q - (i.e. for ID 1, Q 4, it would give me None, Read Aloud, Distract, Overall). I see why this is happening, but I can't seem to find the fix that gives me what I want even though I know it must be simple and is staring straight at me! As an extension, I may want to then expand Answer into up to 6 columns, but I can figure that part out once I get there. Thanks!
... View more