Reputation: 1
I have a strange problematic, it try to solve with an array. Here's the thing : i have this dataset :
Variable Code is an id for a type of expense. Amount is the amount of the expense. What i'ld like to do is create a column for each code and put the amount of the expense in it.
I tried different things to get this results with array like :
data Want;
set Have;
array _Code{*} 3MC 7MC 7GI 7GT;
do i = 1 to dim (_Code);
if code=_Code{i} then _Code{i}=Amount ;
end;
run;
Does anyone have an idea how i can fix this ? Thanks !
Upvotes: 0
Views: 312
Reputation: 51566
Seems like a silly structure to create, but PROC TRANSPOSE can do it.
data have;
input name :$32. value ;
cards;
3MC 12.5
7MC 23
;
proc transpose data=have out=want(drop=_name_);
by name value;
id name;
var value;
run;
Results
Obs name value _3MC _7MC
1 3MC 12.5 12.5 .
2 7MC 23.0 . 23
Notice how SAS had to modify your character variable's values to make them into names that could be used as variable names. SAS names cannot start with a digit. Only a letter or an underscore.
Upvotes: 1