|
REPLACEName:
Dataplot does the following:
The motivation for adding this command was to address the problem where you have two sets of labs (each data set contains a lab-id and a corresponding measurement) and you need to create a new data set that contains the data for the labs that are common to both sets. The program example below demonstrates how the REPLACE command can help accomplish this.
<SUBSET/EXCEPT/FOR qualification> where <groupid> is a variable (typically a group-id variable); <group2> is a variable (typically a group-id variable); <y1> is a variable containing the values to be extracted; <y2> is a variable where the extracted values from <y1> are placed; and where the <SUBSET/EXCEPT/FOR qualification> is optional. The <groupid> and <group2> variable do not need to be the same length. The <y2> variable should be a previously existing variable.
<SUBSET/EXCEPT/FOR qualification> where <groupid> is a variable (typically a group-id variable); <group2> is a variable (typically a group-id variable); <y2> is the returned variable; and where the <SUBSET/EXCEPT/FOR qualification> is optional. This is an abbreviated syntax where the <y1> variable is assummed to be all 1's. The <groupid> and <group2> variable do not need to be the same length. The <y2> variable should be a previously existing variable.
LET Y2 = REPLACE LAB1 LAB2 LET Y2 = REPLACE LAB1 LAB2 Y1 SUBSET LAB1 > 2
. Problem:
.
. We have 2 sets of labs and we want to create a new
. data set that contains the labs common to both sets
. (for each set, there is a lab-id and a measurement).
.
. Step 1: Create some data
.
let lab1 = data 1 3 4 5 7 8 11 13 15 16 18 19
let n1 = size lab1
let y1 = norm rand numb for i = 1 1 n1
.
let lab2 = data 1 2 5 6 8 12 15 18 20
let n2 = size lab2
let y2 = norm rand numb for i = 1 1 n2
.
. Step 2: Identify the common labs
.
let labint = set intersection lab1 lab2
.
. Step 3: Create the tag variables for
. each lab
.
let tag1 = 0 for i = 1 1 n1
let tag1 = replace lab1 labint
.
let tag3 = 0 for i = 1 1 n2
let tag3 = replace lab2 labint
.
. Step 5: Retain the common labs
.
set write decimals 2
retain y1 lab1 subset tag1 = 1
retain y2 lab2 subset tag3 = 1
print lab1 y1 y2
The following output is generated:
1.00 -1.07 -0.10
5.00 0.23 0.26
8.00 -0.53 0.03
15.00 1.19 0.39
18.00 -0.15 -0.47
Date created: 4/14/2006 |