SAS Programming

DATA Step, Macro, Functions and more
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 🙂

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 855 views
  • 1 like
  • 2 in conversation