BookmarkSubscribeRSS Feed
wajmsu
Obsidian | Level 7

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

4 REPLIES 4
Reeza
Super User

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

wajmsu
Obsidian | Level 7

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

Reeza
Super User

 

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

 

wajmsu
Obsidian | Level 7

Thanks. Can you give me the code?

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 825 views
  • 1 like
  • 2 in conversation