SAS notes (8) using arrays to reconstruct SAS datasets

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.