BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GregG
Quartz | Level 8

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
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;
andreas_lds
Jade | Level 19
Please note, that for most procedures the structure of have is more useful, than that of want.
novinosrin
Tourmaline | Level 20

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!

 

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 920 views
  • 1 like
  • 3 in conversation