BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
asgee
Obsidian | Level 7

Hi all, 

 

Repeated measures data is frying my brain 😣... I'm working on a dataset that has multiple visits overtime. I want to reduce the visits per ID down to just one observation per ID. A sample of the data is below:

ID

Visit

Label

AAA

1

.

AAA

2

No

AAA

3

Yes

BBB

1

.

BBB

2

Yes

CCC

1

Yes

DDD

1

.

DDD

2

No

DDD

3

No

EEE

1

.

EEE

2

.

FFF

1

Yes

GGG

1

No

HHH

1

.

HHH

2

.

HHH

3

.

 

Everything is sorted in chronological order based on their visit (1->2->3->etc.). Basically I have three criteria to follow per ID:

1) If the ID has at least one label with a "Yes", pick the row where a "Yes" label first appears

2) If the ID ONLY has "No" / "missing" labels across all visits, pick the row where a "No" label first appears.

3) If the ID ONLY has missing observations across all visits, pick the row where a missing label first appears.

 

Initially, the code I have only reduces the observations down to their very first visit (regardless of their label). Now I'm having trouble with coding the part of identifying "the first time a "___" appears". 

 

I'd want to hopefully produce a table that looks something like this:

ID

Visit

Label

AAA

3

Yes

BBB

2

Yes

CCC

1

Yes

DDD

2

No

EEE

1

.

FFF

1

Yes

GGG

1

No

HHH

1

.

 

Any help or advice would be really appreciated! 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @asgee  Solution plagiarized from @Reeza . She stumped with me with this elegant approach. I don't like intelligent people

 




data have;
input ID $	Visit	Label $;
cards;
AAA	1	.
AAA	2	No
AAA	3	Yes
BBB	1	.
BBB	2	Yes
CCC	1	Yes
DDD	1	.
DDD	2	No
DDD	3	No
EEE	1	.
EEE	2	.
FFF	1	Yes
GGG	1	No
HHH	1	.
HHH	2	.
HHH	3	.
;

proc sort data=have out=_have;
 by id descending label;
run;

data want;
 set _have;
 by id;
 if first.id;
run;



View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi @asgee  Solution plagiarized from @Reeza . She stumped with me with this elegant approach. I don't like intelligent people

 




data have;
input ID $	Visit	Label $;
cards;
AAA	1	.
AAA	2	No
AAA	3	Yes
BBB	1	.
BBB	2	Yes
CCC	1	Yes
DDD	1	.
DDD	2	No
DDD	3	No
EEE	1	.
EEE	2	.
FFF	1	Yes
GGG	1	No
HHH	1	.
HHH	2	.
HHH	3	.
;

proc sort data=have out=_have;
 by id descending label;
run;

data want;
 set _have;
 by id;
 if first.id;
run;



asgee
Obsidian | Level 7
Hi @novinosrin (& @Reeza), thanks for your help, the code works perfectly! Ahahah both you and Reeza are amazing intelligent people, can't thank you enough both for all your help.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 910 views
  • 1 like
  • 2 in conversation