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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.