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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

1 REPLY 1
Linlin
Lapis Lazuli | Level 10

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 364 views
  • 0 likes
  • 2 in conversation