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

hi,

I have a dataset like this;

ID             A              B          C       D

1              21          45          90     76

1              25          32          78      21

2             34           74           34     89

2             43            88          12      94

2             54            33          77      90

I want to do transposing and the desired o/p will be like

ID        _name_     value

1              A             21

1              B             45

1              C             90

1              D             76

1              A              25

1              B              32

1              C              78

1              D              21

2              A              34

2              B              74

2              C              34

2              D              89

...............and so on...

how can i do this?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data have;
input ID A B C D;
datalines;
1 21 45 90 76
1 25 32 78 21
2 34 74 34 89
2 43 88 12 94
2 54 33 77 90
;

data want(keep= ID _name_ value);
   set have;
   array _{4} A B C D;
   do i=1 to dim(_);
      _name_=vname(_[i]);
      value=_[i];
      output;
   end;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20
data have;
input ID A B C D;
datalines;
1 21 45 90 76
1 25 32 78 21
2 34 74 34 89
2 43 88 12 94
2 54 33 77 90
;

data want(keep= ID _name_ value);
   set have;
   array _{4} A B C D;
   do i=1 to dim(_);
      _name_=vname(_[i]);
      value=_[i];
      output;
   end;
run;
AKHILA
Obsidian | Level 7

thank you somuch. it works

PeterClemmensen
Tourmaline | Level 20

Anytime, glad to help 🙂

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1142 views
  • 1 like
  • 2 in conversation