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-wordmark-gradient-background 3.pngSAS Innovate

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 4241 views
  • 2 likes
  • 3 in conversation