In the previous example you created 3 observations from a single observation using an array.In this example,you have 6 values of X (X1 to X6) which represent X at 3 times recorded under 2 different methods.This requires a change from a simple array to a multidimensional array.Suppose, again, that you have the data set OLD with one observation per subject.This time, however, you have recorded both the time of the observation as well as the method under which the measurement was taken.
Each record contains variables X1-X6.Variables X1-X3 represent values of measurements taken for method 1,at times 1 to 3; variables X4-X6 represent values for method 2, also at times 1 to 3.You now want to create data set NEW with six observations per subject, one for each time-method combination.You also wish to create two new variables, METHOD and TIME, for each observation.
Here is the program that accomplishes your goal:
This program is much like the previous one, except it is in two dimensions,so it must be twice as good - certainly twice as complicated and twice as powerful. Once again, you use XX for the name of the array and X for the name of the new variable in data set NEW which will represent the measurements 0.
This time you create METHOD as a new variable as well as TIME.You do this in DO loops as before, but this time you use two nested loops, one for each dimension in the array.In nested DO loops,inner loops change faster than outer loops. In your OLD data, the measurements occur in the order: method 1-time 1, methodl-time2, methodl- time3,method2-timel, method2-time2, and method2-time3, contained in variables X1-X6.
Since time is changing from 1 through 3 within each static method, time is said to vary faster than method.This pattern can be represented in a multidimensional "2 by 3" array. Multidimensional arrays are identified by a list of array dimensions, separated by commas, with slower changing dimensions preceding faster changing ones in the list from left to right. Array XX has dimensions [2,3], and is made up of variables XI- X6.This means that XX[1,1] represents XI (method 1-time 1), XX[1,2] represents X2 (methodl-time2), and so forth, up to XX[2,3] which represents X6 (method2-time3).
The nested loops read through the data in OLD sequentially from XI through X6 and assign the proper values to variables METHOD and TIME before outputting each observation to data set NEW.First the outer DO METHOD loop sets the variable METHOD to 1 or 2 0. Next, the inner DO TIME loop cycles through the three times for each method ©.Each element of the array is therefore selected, identified as to method and time 0, and output as X to data set NEW.©
Easy? Not necessarily. Powerful? Definitely! Maybe you should LOOP through this section a few more TIMEs using different METHODs until you've got it.
SAS Programming Related Tutorials
|SASS (Syntactically Awesome Style sheets) Tutorial||R Programming language Tutorial|
SAS Programming Related Interview Questions
|Logistics Interview Questions||SAS Programming,SQL server Interview Questions|
|Clinical SAS Interview Questions||SASS (Syntactically Awesome Style sheets) Interview Questions|
|SQL Server Analysis Services (SSAS) Interview Questions||R Programming language Interview Questions|
|SAS DI Interview Questions||Advanced SAS Interview Questions|
|Base Sas Interview Questions||SAS Macro Interview Questions|
|Clinical Data Management Interview Questions|
Sas Programming Tutorial
Input And Infile
Set, Merge, And Update
Table Lookup Tools
Proc Means And Proc Uimivariate
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.