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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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