Hi. In the following data, I want to do the following:
1. split the Age variable into two variables - age and sex using the "/" as the condition in the Age variable
2. In the remaining age variable for all ages less than a year, replace it with "1". For example, in observation 2 and 3 below, the age variable would be "1" for both
3. split the ApptTime variable into two variables - ApptDate and ApptTime by the space in between. For example, in "30-11-2023 12:30", ApptDate == 30-11-2023 and ApptTime==12:30
4. convert the ApptDate from a string to a date variable
Any help would be much appreciated.
1. split the Age variable into two variables - age and sex using the "/" as the condition in the Age variable
2. In the remaining age variable for all ages less than a year, replace it with "1". For example, in observation 2 and 3 below, the age variable would be "1" for both
3. split the ApptTime variable into two variables - ApptDate and ApptTime by the space in between. For example, in "30-11-2023 12:30", ApptDate == 30-11-2023 and ApptTime==12:30
4. convert the ApptDate from a string to a date variable
Any help would be much appreciated.
Code:
input str15 MRNo str8 Age str17 ApptTime "P1610634" "68/F" "30-11-2023 12:30" "P1602163" "1 Mo. /M" "30-11-2023 08:40" "P1602154" "7 Mo. /M" "30-11-2023 08:40" "PN1585614" "1/F" "30-11-2023 11:45" "PN1401224" "2/M" "30-11-2023 11:30" "P1609543" "63/M" "30-11-2023 11:25" "P1610326" "46/F" "30-11-2023 11:10" "P1257195" "4/F" "30-11-2023 10:05" "P1411821" "2/M" "30-11-2023 09:50" "P1539542" "30/M" "30-11-2023 09:45" "P1610610" "69/F" "30-11-2023 09:30" "N500364" "50/M" "30-11-2023 09:30" "KVC-P145026" "57/F" "30-11-2023 09:15" "P352115" "33/F" "30-11-2023 09:15" "P1541985" "26/F" "30-11-2023 09:00" "P1519669" "21/F" "30-11-2023 09:00" "P1598091" "73/M" "30-11-2023 09:00" "N492028" "9/M" "30-11-2023 09:00" "P1598574" "67/M" "30-11-2023 08:30" "N498303" "52/F" "29-11-2023 16:00" "N498303" "52/F" "29-11-2023 16:00" "N473563" "11/M" "29-11-2023 15:45" "P1345781" "31/F" "29-11-2023 15:30" "P1555159" "26/F" "29-11-2023 15:15"
Comment