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

Good day! My data looks like this:

ID      B1 B2 B3

1        1   2   3

2        4   5   6             

3        7   8   9

 

I would like it to look like this:

ID    B# Content

1       1      1

1       2      2

1       3      3

2       1      4

2       2      5

2       3      6

3       1      7

3       2      8

3       4      9

 

Could you pls help me. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

In addition to transposing, you could do it in a data step. I assume your last row is a typo, though. I don't know where the b# = 4 would come from.

 

data have;
    input ID B1 B2 B3;
datalines;
1 1   2   3
2 4   5   6
3 7   8   9
;

data want(drop = b:);
    set have;
    array b{3};
    do num_b = 1 to 3;
        content = b(num_b);
        output;
    end;
run;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Without test data in the form of a datastep, this is just a guess:

proc transpose data=have out=want;
  by id;
  var b:;
run;
collinelliot
Barite | Level 11

In addition to transposing, you could do it in a data step. I assume your last row is a typo, though. I don't know where the b# = 4 would come from.

 

data have;
    input ID B1 B2 B3;
datalines;
1 1   2   3
2 4   5   6
3 7   8   9
;

data want(drop = b:);
    set have;
    array b{3};
    do num_b = 1 to 3;
        content = b(num_b);
        output;
    end;
run;
cdvdc
Calcite | Level 5

thank you so much! the last one was a typo 

collinelliot
Barite | Level 11

You're welcome. @RW9' s solution would probably work for you, too, and you should probably get familiar with how proc transpose works since there are times when it will be far easier than a data step approach. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1481 views
  • 3 likes
  • 3 in conversation