I'm trying to transpose a dataset in the following way.
Input:
id var item value
2 q1 . 1
4 q2 2 3
7 q2 5 3
8 q2 6 4
10 q3 1 2
23 q4 . 4
24 r1 . 5
data have; input id var $ item value; cards; 2 q1 . 1 4 q2 2 3 7 q2 5 3 8 q2 6 4 10 q3 1 2 23 q4 . 4 24 r1 . 5 ; run; PROC SORT data = have; BY id var; run; PROC TRANSPOSE data = have out = want delimiter=_; by id; id var item; var value; run;The issue i have here is that i cannot transpose the variables where ITEM is an empty variable. Compared to the desired output i receive a table without q1, q4 and r1. How can i deal with the empty variables when transposing?
Don't know what you want to do with the transposed format, but here you go:
data pre_want;
set have;
length key $ 4; /* needs adjustment */
key = ifc(missing(item), ' ', put(item, 1.));
key = catx('_', var, key);
drop var item;
run;
proc transpose data=pre_want out=want;
by key;
id id;
var value;
run;
You need to concatenate "var" and "item" before proc transpose.
Don't know what you want to do with the transposed format, but here you go:
data pre_want;
set have;
length key $ 4; /* needs adjustment */
key = ifc(missing(item), ' ', put(item, 1.));
key = catx('_', var, key);
drop var item;
run;
proc transpose data=pre_want out=want;
by key;
id id;
var value;
run;
You need to concatenate "var" and "item" before proc transpose.
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.
Ready to level-up your skills? Choose your own adventure.