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

Hi,

I have the following data with these variables. For the same ID, the race/ethnicity is different, when it is supposed to be the same.

 

ID_personAdmit DateRaceEthnicity
12341/03/2019Non-Hispanic Black
12342/06/2019Non-Hispanic White
34215/14/2020Hispanic
34213/21/2021Non-Hispanic White
45366/4/2020Unknown

 

To standardize the race/ethnicity information, I decided to make the race/ethnicity for each ID same as it was at the earliest admission date. How do I code for this?

I need the data to be like this:

 

ID_personAdmit DateRaceEthnicityRaceeth_new
12341/03/2019Non-Hispanic BlackNon-Hispanic Black
12342/06/2019Non-Hispanic WhiteNon-Hispanic Black
34215/14/2020HispanicHispanic
34213/21/2021Non-Hispanic WhiteHispanic
45366/4/2020UnknownUnknown
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Assuming your data is sorted by ID_person and Admit_Date

 

data want;
    set have;
    by id_person;
    retain raceeth_new;
    if first.id_person then raceeth_new=racethnicity;
run;


Code is untested, as I cannot test the code against your screen captures (I can only test code against SAS data sets, please from now on provide SAS data sets as working SAS data step code, which you can type in yourself or follow these instructions)

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Assuming your data is sorted by ID_person and Admit_Date

 

data want;
    set have;
    by id_person;
    retain raceeth_new;
    if first.id_person then raceeth_new=racethnicity;
run;


Code is untested, as I cannot test the code against your screen captures (I can only test code against SAS data sets, please from now on provide SAS data sets as working SAS data step code, which you can type in yourself or follow these instructions)

--
Paige Miller
Gayatrikunchay
Obsidian | Level 7

Hi, this worked great! But what if the earliest admission date has 'Unknown" Race and Ethnicity? How do I code to take the race/ethnicity for next admission date? Thank you!

PaigeMiller
Diamond | Level 26

Delete the rows with missing RACEETHNICITY and then run my code.

--
Paige Miller
Gayatrikunchay
Obsidian | Level 7

I cannot delete the rows as I have other variables which has important information. Any other way?

PaigeMiller
Diamond | Level 26

@Gayatrikunchay wrote:

I cannot delete the rows as I have other variables which has important information. Any other way?


Delete the rows, run my code, obtain one row per ID, and then merge the results ReceEthnicity_new back into the original data set by ID, then no rows are missing.

--
Paige Miller
Gayatrikunchay
Obsidian | Level 7

This worked!! Thank you!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 428 views
  • 2 likes
  • 2 in conversation