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

Hi,

I have a data something like this

IDVisit dateGender of Sex partner
112639/1/20172
112639/6/20179
112639/13/20179
117369/4/20181
117369/14/20189
118916/6/20179
118917/17/20172
118918/2/20172
118948/9/20179
118949/18/20179
118939/21/20173
1189310/20/20179

gender of sex partners(gender_sp) code is 1=male, 2-female, 3=both, 9=unknown

I want to copy mostly prior visit's gender of sex partners' info to other visits . in some situation gender of sex partner is missing in fist visit but is available in second visit.  I want to copy gender of sp to all visit if it is the same patient. How can i do this? I have 9588 records cannot fix this manually. Please help. SAS community is a GREAT resource for me.  

i want like this from the previous table

IDVisit dateGender of Sex partner
112639/1/20172
112639/6/20172
112639/13/20172
117369/4/20181
117369/14/20181
118916/6/20172
118917/17/20172
118918/2/20172
118948/9/20179
118949/18/20179
118939/21/20173
1189310/20/20173
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

It would help if you provided data following these instructions so we could test out the results.

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

As it is, I can't test my code on your data, so consider this to be UNTESTED CODE

 

proc transpose data=have out=have_t;
    by id;
    var gender_of_sex_partner;
run;
data have_t2;
    set have_t;
    gender_of_first_partner=coalesce(of col:);
run;
data want;
    merge have have_t2(keep=id gender_of_first_partner);
    by id;
run;

If it doesn't work (because it is UNTESTED CODE), please provide (a portion of) your data in the format requested.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

It would help if you provided data following these instructions so we could test out the results.

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

As it is, I can't test my code on your data, so consider this to be UNTESTED CODE

 

proc transpose data=have out=have_t;
    by id;
    var gender_of_sex_partner;
run;
data have_t2;
    set have_t;
    gender_of_first_partner=coalesce(of col:);
run;
data want;
    merge have have_t2(keep=id gender_of_first_partner);
    by id;
run;

If it doesn't work (because it is UNTESTED CODE), please provide (a portion of) your data in the format requested.

--
Paige Miller
Dhana18
Obsidian | Level 7
Thank you. It worked!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 406 views
  • 0 likes
  • 2 in conversation