SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to change observations to variables

Accepted Solution Solved
Reply
Contributor
Posts: 59
Accepted Solution

How to change observations to variables

Hello all, 

 

I'm hoping you can help me with some code to change observations to variables, I have data with a structure like so: 

 

ID     Date   UniqueVal

1        D1         111

1        D2         222

1        D3         333

2        D1         111

2        D2         222

2        D3         333

3        D1         111

3        D2         222

3        D3         333

 

 

I want: 

 

ID     D1                 D2                  D3

1     111                 222                 333

2     111                 222                 333

3     111                 222                 333

 

 

 

Hopefully that makes sense. Anyway, thank you in advance for your guidance. 


Accepted Solutions
Solution
‎02-11-2018 06:45 PM
PROC Star
Posts: 1,577

Re: How to change observations to variables

data have;
input ID     Date $   UniqueVal;
datalines;
1        D1         111
1        D2         222
1        D3         333
2        D1         111
2        D2         222
2        D3         333
3        D1         111
3        D2         222
3        D3         333
;

proc transpose data=have out=want(drop=_name_);
by id;
var UniqueVal;
id date;
run;

View solution in original post


All Replies
PROC Star
Posts: 1,577

Re: How to change observations to variables

did you try proc transpose?

Contributor
Posts: 59

Re: How to change observations to variables

Posted in reply to novinosrin
I have messed with it yes, but I couldn't produce the results I needed. Could you provide example code? Thank you!
Solution
‎02-11-2018 06:45 PM
PROC Star
Posts: 1,577

Re: How to change observations to variables

data have;
input ID     Date $   UniqueVal;
datalines;
1        D1         111
1        D2         222
1        D3         333
2        D1         111
2        D2         222
2        D3         333
3        D1         111
3        D2         222
3        D3         333
;

proc transpose data=have out=want(drop=_name_);
by id;
var UniqueVal;
id date;
run;
Contributor
Posts: 59

Re: How to change observations to variables

Posted in reply to novinosrin
Excellent, thank you!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 208 views
  • 2 likes
  • 2 in conversation