🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Fluorite | Level 6

Creating new set with only one observation per subject from last set

this is from BIST0535.hw3_1

As you can see I have sorted data by subject and then dov, such that the observations for a single subject are all clumped together and the observation from the first time they visited (date of visit, dov) is first. I need to create a new data set BIST0535.hw3_2 which contains only one observation from each subject with the first time they visited. I think we are meant to use an IF THEN statement, however if there is a easier way I am open to it.

Obs subject dov dbp sbp
 1 07/09/1998 108 157 1 09/23/1998 107 134 2 10/15/1998 114 149 2 01/14/1999 112 165 2 04/15/1999 105 158 2 07/22/1999 115 143 3 07/22/1998 103 148 3 10/07/1998 107 165 3 01/14/1999 102 159 4 01/23/2000 87 110 4 04/26/2000 85 128 5 11/10/1999 65 137 5 02/10/2000 66 108
1 ACCEPTED SOLUTION

Accepted Solutions
Tourmaline | Level 20

Re: Creating new set with only one observation per subject from last set

if i understand you,

all you need is

if first.subject;

data want;

set have;

by subject dov;

if first.subject;

run;

4 REPLIES 4
Tourmaline | Level 20

Re: Creating new set with only one observation per subject from last set

if i understand you,

all you need is

if first.subject;

data want;

set have;

by subject dov;

if first.subject;

run;

Amethyst | Level 16

Re: Creating new set with only one observation per subject from last set

``````data want;
set have;
by subject;
if first.subject;
run;
``````
Thanks,
Jag
Fluorite | Level 6

Re: Creating new set with only one observation per subject from last set

Thank you! For some reason it was giving me an error about the BY statement, but i guess there was a need for a PROC SORT before this could occur.

Tourmaline | Level 20

Re: Creating new set with only one observation per subject from last set

Yes @MBlack732 By group processing does require ordering

Discussion stats
• 4 replies
• 822 views
• 0 likes
• 3 in conversation