Hi,
I have a data something like this
ID | Visit date | Gender of Sex partner |
11263 | 9/1/2017 | 2 |
11263 | 9/6/2017 | 9 |
11263 | 9/13/2017 | 9 |
11736 | 9/4/2018 | 1 |
11736 | 9/14/2018 | 9 |
11891 | 6/6/2017 | 9 |
11891 | 7/17/2017 | 2 |
11891 | 8/2/2017 | 2 |
11894 | 8/9/2017 | 9 |
11894 | 9/18/2017 | 9 |
11893 | 9/21/2017 | 3 |
11893 | 10/20/2017 | 9 |
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
ID | Visit date | Gender of Sex partner |
11263 | 9/1/2017 | 2 |
11263 | 9/6/2017 | 2 |
11263 | 9/13/2017 | 2 |
11736 | 9/4/2018 | 1 |
11736 | 9/14/2018 | 1 |
11891 | 6/6/2017 | 2 |
11891 | 7/17/2017 | 2 |
11891 | 8/2/2017 | 2 |
11894 | 8/9/2017 | 9 |
11894 | 9/18/2017 | 9 |
11893 | 9/21/2017 | 3 |
11893 | 10/20/2017 | 3 |
It would help if you provided data following these instructions so we could test out the results.
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.
It would help if you provided data following these instructions so we could test out the results.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.