1

I am new to SAS and am trying to rearrange a dataset. I feel that it shouldn't be too hard but I've been struggling with it for quite some time now. Here is what my dataset looks like

Factor Variable Value
A      X        1
A      Y        2
B      X        3
B      Y        4

and I want my resulting dataset to be

Variable   A   B
X          1   3
Y          2   4

Is this possible? Thank you for your help.

BellevueBob
  • 9,498
  • 5
  • 29
  • 56
Marco
  • 1,472
  • 16
  • 29

1 Answers1

3

You want values of variable Value (VAR) to be transposed to columns that will be named by values of Factor (ID) for each value of Variable (BY), while not keeping the name of Value in an output field _NAME_ (drop=_NAME_). I do admit I always need to play with it to get what I need.

data in;
length Factor Variable $1 Value 8;
input Factor Variable Value;
cards;
A      X        1
A      Y        2
B      X        3
B      Y        4
;
run;

proc sort data=in;
BY Variable;
run;

proc transpose data=in out=transp (drop=_NAME_);
ID Factor;
BY Variable;
VAR value;
run;

proc print noobs;run;
vasja
  • 4,732
  • 13
  • 15
  • I always remember it by knowing that the `by` statement goes down the left, the `var` statement make up the metrics or the data that you want to keep and the `id` and `idlabel` statements make up the column names. So the `by` and the `var` statements behave similar to `proc means` etc... – Robert Penridge Jul 29 '12 at 01:17