In practical applications, we often convert wide data (one patient observation) into long data (one patient observation) or long data (one patient multiple observations) into wide data (one observation for a patient), and in R we can use the Reshape2 package. There are two implementations of the SAS: arrays and transpose. This blog post first explains the use of arrays to reconstruct SAS data, and the next blog post will introduce the use of the transpose function to reconstruct SAS data.
1. Wide data variable length data
***create DataSet data diagnose; INPUT @1 Patno 2. @3DATE MMDDYY10. @DX1-DX3; FORMAT DATE MMDDYY10.;D Atalines;10/21/1999 1 2 .10/29/1999 on 2 . .11/11/2000 on 3 . .01/01/2000 1 2 302/02/2000 3 2 .03/15/2000 on 4 . .;***Convert wide data to long data without using the array data new_dx; SET Diagnose (DROP=DATE); DX=DX1; IF DX NE. Then OUTPUT; DX=DX2; IF DX NE. Then OUTPUT; DX=DX3; IF DX NE. Then OUTPUT; KEEP Patno DX; RUN;***Convert wide data into Long data, using array data new_dx; SET Diagnose (DROP=DATE); ARRAY dxarray[3] DX1-DX3; Do I= 1 to 3; DX=Dxarray[i]; IF DX NE. Then OUTPUT; END; KEEP Patno DX; RUN;
2. Convert Long data to wide data
References: longitudinal Data and Sas:a Programmer ' s Guide
SAS notes (8) using arrays to reconstruct SAS datasets