create single observation from multiple observation

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

create single observation from multiple observation

here is dataset

no  x   y   z    year

1    a            2010

1       b        2010

1           c   2010

1 a              2011

1     b         2011

1         c     2011

2 a              2009

2      b        2009

2        c     2009

How to convert it in below manner

no x y z  year

1  a  b  c 2010

1  a  b  c  2011

2 a  b c  2009


Accepted Solutions
Solution
‎07-06-2012 11:24 AM
Super Contributor
Posts: 1,636

Re: create single observation from multiple observation

borrowed Astounding's code:

data have;
input no  (x   y   z) (:$)    year;
if x='1' then x='';
if y='1' then y='';
if z='1' then z='';
cards;
1    a   1 1         2010
1     1  b  1      2010
1      1  1   c   2010
1  a   1    1       2011
1   1  b  1       2011
1    1  1   c     2011
2  a   1   1        2009
2   1   b   1     2009
2   1  1   c     2009
;
data want;
   update have (obs=0) have;
   by no year;
  
run;
proc print;run;

Obs    no    x    y    z    year

1      1    a    b    c    2010
2      1    a    b    c    2011
3      2    a    b    c    2009

Linlin

View solution in original post


All Replies
Solution
‎07-06-2012 11:24 AM
Super Contributor
Posts: 1,636

Re: create single observation from multiple observation

borrowed Astounding's code:

data have;
input no  (x   y   z) (:$)    year;
if x='1' then x='';
if y='1' then y='';
if z='1' then z='';
cards;
1    a   1 1         2010
1     1  b  1      2010
1      1  1   c   2010
1  a   1    1       2011
1   1  b  1       2011
1    1  1   c     2011
2  a   1   1        2009
2   1   b   1     2009
2   1  1   c     2009
;
data want;
   update have (obs=0) have;
   by no year;
  
run;
proc print;run;

Obs    no    x    y    z    year

1      1    a    b    c    2010
2      1    a    b    c    2011
3      2    a    b    c    2009

Linlin

☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 177 views
  • 0 likes
  • 2 in conversation