I need help in programming part for date imputation. Here is the raw data below:
input id date $ 10.;
I need to do date imputation based on two points as below:
1. If both month and day are missing, then set to December 31.
2. If only day is missing, then set to last day of the month.
/*Seperate date into day, month, year */
if yearc ne "unkk" then do; /*One row has year missing, not able to impute */
/*both month and day missing*/
if dayc="uk" and monthc="unk" then do;
/*only day missing*/
if dayc="uk" and monthc ne"unk" then do;
/*get imputed date*/
if dayi ne "" and monthi ne "" then
if lastday ne . then date_impc=put(lastday, date9.);
format date_imp date9.;
I already posted an answer to this in the thread that has been deleted in the meantime:
data want; set have (rename=(date=_date)); if substr(_date,6) = "unkk" then date =.; else do; if substr(_date,3,3) = "unk" then substr(_date,3,3) = "dec"; if substr(_date,1,2) = "uk" then do; substr(_date,1,2) = "01"; date = input(_date,date9.); date = intnx('month',date,0,'e'); end; else date = input(_date,date9.); end; format date yymmdd10.; * always use the ISO format for clarity; drop _date; run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.