SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Stacking matched controls under respective cases

Reply
Contributor
Posts: 61

Stacking matched controls under respective cases

Hi all,

I need to make a sub-dataset out of the main data in a way that two controls are stacked below their respective case.  Any opinion or hint!
Thanks

Super User
Posts: 17,963

Re: Stacking matched controls under respective cases

[ Edited ]

1. Number each Case/Control set with a unique ID -> SetID

2. Create a variable where Case are 1, controls are 2 ->Case_Control

 

Then you can sort by SetID, Case_Control

Contributor
Posts: 61

Re: Stacking matched controls under respective cases

Thanks Reeza!

 

Attached is my sample datasets wtih id numbers from sample and controls as paris; can you guide me how to do stacking with individual paris together?

 

data sample;
input id age edu race parity wt ht;
datalines;
05 32 9 1 0 90 5.2
12 35 12 1 2 110 5.0
17 40 10 2 1 130 4.9
22 25 14 3 0 110 5.4
29 27 12 2 1 95 5.0
40 28 10 3 2 130 6
;
data controls;
input id age edu race parity wt ht;
datalines;
10 33 11 2 1 98 5.7
11 35 10 2 2 120 5.9
19 42 11 1 3 139 5.9
26 26 14 0 1 99 5.0
31 27 10 2 1 95 5.5
32 29 12 2 2 125 6.2
37 31 10 2 1 190 7.2
43 35 12 1 1 110 5.0
46 45 10 1 1 130 4.9
51 28 12 3 0 110 5.4
55 22 10 1 1 95 5.0
58 28 10 3 2 130 6
70 32 9 1 0 90 5.2
79 37 11 1 2 110 5.0
85 48 14 2 1 130 4.9
88 29 14 3 0 110 5.4
90 25 14 2 1 95 5.0
93 27 11 3 2 130 6
99 35 10 1 0 90 5.2
101 33 11 1 2 110 5.0
114 38 16 2 1 130 4.9
125 25 13 3 0 110 5.4
129 25 10 2 1 95 5.0
130 24 11 3 2 130 6
;
run;



Matched pairs with original IDs

Sample

Control 1

Control 2

5

70

99

12

43

101

22

125

51

Super User
Posts: 17,963

Re: Stacking matched controls under respective cases

 

ie create a table that looks like the following from your third table. Them merge in table 1/2  by ID and sort by N and Type2, I would recommend SQL.

 

N   Type    Type2  ID
1   Sample   1   5
1   Control   2   70
1   Control   2   99
2   Sample   1  12
2   Control   2   43
2   Control   2   101

 

Contributor
Posts: 61

Re: Stacking matched controls under respective cases

Thanks. Can you give me the code?

 

Ask a Question
Discussion stats
  • 4 replies
  • 256 views
  • 1 like
  • 2 in conversation