I need what I think is some fairly basic help with proc transpose. I've read a few docs and guides, but can't seem to put everything together to make it work for my exact scenario.
How do I use a proc transpose to turn my DATA HAVE into my DATA WANT?
data have;
input stuid courseid facid qid qresponse $;
cards;
1 1 1 1 5
1 1 1 2 4
1 1 1 3 4
1 1 1 4 5
1 1 1 5 3
1 1 2 1 5
1 1 2 2 5
1 1 2 3 5
1 1 2 4 5
1 1 2 5 5
;
run;
data want;
input stuid courseid facid qid_1 qid_2 qid_3 qid_4 qid_5 $;
cards;
1 1 1 5 4 4 5 3
1 1 2 5 5 5 5 5
;
run;
data have;
input stuid courseid facid qid qresponse $;
cards;
1 1 1 1 5
1 1 1 2 4
1 1 1 3 4
1 1 1 4 5
1 1 1 5 3
1 1 2 1 5
1 1 2 2 5
1 1 2 3 5
1 1 2 4 5
1 1 2 5 5
;
run;
proc transpose data=have out=want(drop=_:) prefix=qid_;
by stuid courseid facid;
id qid;
var qresponse;
run;
data have;
input stuid courseid facid qid qresponse $;
cards;
1 1 1 1 5
1 1 1 2 4
1 1 1 3 4
1 1 1 4 5
1 1 1 5 3
1 1 2 1 5
1 1 2 2 5
1 1 2 3 5
1 1 2 4 5
1 1 2 5 5
;
run;
proc transpose data=have out=want(drop=_:) prefix=qid_;
by stuid courseid facid;
id qid;
var qresponse;
run;
Hi @andreas_lds Very good point. But I would like to bring to your attention one potential caveat. A lot of survey questionnaire data that's used by market research firms are usually in the wide form however transformed into 1's and 0's for regression modeling and so on.
There's a possibility the OP might have such requirement. And then of course even if there's a combination of continuous/non continuous variables, we could analyse interaction terms and so on and so forth.
At DePaul Uni, we play with such data a lot 🙂
Otherwise, I totally agree with you. Cheers!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.