Dear all,
suppose to have the following dataset:
data DB;
input ID :$20. Start :$20. End :$20. TypeTransfusion1 :$20. TypeTransfusion2 :$20. TypeTransfusion3 :$20. Result1 :$20. Result2 :$20. Result3 :$20.;
cards;
0001 2024-09-01 2024-10-01 RBC Whole blood . Positive Positive .
0001 2024-09-01 2024-10-01 . . Platelet . . Negative
0002 2016-NK-NK 2016-NK-NK . Whole blood Platelet . Negative Positive
0002 2016-05-02 2016-05-02 RBC Whole blood . Positive Positive .
0002 2016-05-05 2016-05-04 . . Platelet . . Negative
0003 . . . . . . . .
0003 . . . . . . . .
0004 2024-09-01 2024-10-01 RBC Whole blood . Negative Positive .
0004 2024-09-01 2024-10-01 . . Platelet . . Positive
0005 2025-11-03 2025-11-23 . Whole blood . . Positive .
0005 2025-11-03 2025-11-14 RBC . . Negative . .
;
run;
In one of my previous posts named: "From short to long format for SDTM programming," I asked for support to transpose the dataset.
Gently the following help was provided to me:
data want2;
set db;
length TypeTransfusion $20;
array list TypeTransfusion1-TypeTransfusion3 ;
do index=1 to dim(list);
TypeTransfusion=list[index];
output;
end;
drop TypeTransfusion1-TypeTransfusion3;
run;
The initial dataset contained only the "TypeTransfusion*" variable. Now, another variable "Result*" has been added. How can I integrate this new variable into the code above? In other words, I need to do the same thing that I do for the TypeTransfusion variable also for the Result variable in the same piece of code above.
Can anyone help me please?
Best
Try the following:
data want2;
set db;
length TypeTransfusion result $20;
array list TypeTransfusion1-TypeTransfusion3 ;
array list_r result1-result3;
do index=1 to dim(list);
TypeTransfusion=list[index];
result=list_r[index];
output;
end;
drop TypeTransfusion1-TypeTransfusion3 result1-result3;
run;
What did you try? How did it go? Did you get any errors in the log?
You just need to add two statements and modify one other.
data want2;
set db;
length TypeTransfusion $20;
array list TypeTransfusion1-TypeTransfusion3 ;
array list2 Result1-Result3;
do index=1 to dim(list);
TypeTransfusion=list[index];
Result=list2[index];
output;
end;
drop TypeTransfusion1-TypeTransfusion3 Result1-Result3;
run;
Can you see why that did not work?
Do you see the pattern that will emerge in the output?
Hint:
Best would be to show an example of the expected result for your "transpose" of the example data.
Note that "doesn't do the job" does not provide any detail about what was missing (or extra) or what is actually wrong with the resulting data set.
A likely incomplete guess on my part as to part of the objection about the output data set would be the repeated values of the last TypeTransfusion but I am sure that is not the only bit.
Try the following:
data want2;
set db;
length TypeTransfusion result $20;
array list TypeTransfusion1-TypeTransfusion3 ;
array list_r result1-result3;
do index=1 to dim(list);
TypeTransfusion=list[index];
result=list_r[index];
output;
end;
drop TypeTransfusion1-TypeTransfusion3 result1-result3;
run;
@NewUsrStat wrote:
Could you please give me an example? Thank you very much!
Please note Tom's first answer. He already provided a full example, almost identical to Kathryn's.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.