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

Hello,

    I have multiple rows of patient data with a repeating ID, but the data contained within each row is different. The patient ID on top is the one I'd like to remove:

data have;

studyid     age    sex     los    cause of injury

2048         34        F        3       MVA

2048         33        F        4       MCC

data want;

studyid     age    sex     los    cause of injury

2048         33        F        4       MCC

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You are correct, I read it wrong, it should be last.StudyID not first.StudyID.
If last.studyID would be the equivalent and works for all situations regardless of multiples or a single study ID.

View solution in original post

7 REPLIES 7
Reeza
Super User
Is it always the first one?

data want;
set have;
by studyID;
if first.studyID;
run;
novinosrin
Tourmaline | Level 20

Agree with @Reeza  's solution. I am making the assumption to account for a case where there's just one studyid record 

data have;
infile cards truncover;
input (studyid     age    sex     los    causeofinjury) ($);
cards;
2048         34        F        3       MVA
2048         33        F        4       MCC
;

data want;
 set have;
 by studyid;
 if first.studyid and last.studyid or not first.studyid;
run;

 

Reeza
Super User
I think my solution works even if the StudyID has only one record, because that would still be the first record.
novinosrin
Tourmaline | Level 20

Oops @Reeza  the OP doesn't want the 1st record. Am i mistaken?

"The patient ID on top is the one I'd like to remove:"

Reeza
Super User
You are correct, I read it wrong, it should be last.StudyID not first.StudyID.
If last.studyID would be the equivalent and works for all situations regardless of multiples or a single study ID.
novinosrin
Tourmaline | Level 20

@Reeza  Are you assuming all by groups to have only 2 records for last.studyid alone check? 

Reeza
Super User
I'm assuming that you'd only keep the last record. You're assuming that you only remove the first record. Given the data, I highly suspect it would make sense to only include the last record but only OP can clarify that issue.

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
  • 7 replies
  • 818 views
  • 2 likes
  • 3 in conversation