I have a variable, dod, that contains the date of death as yearmo and does not contain days. How do I add the first of every month (01) to the end of every case in the dod column and then change the format to match year-mo-da?
Here is an example of the data:
dod
201705
201304
201709
201608
Once I add the days as 01 to every case, how do I chance to the below format?
dod_formatted
2017-05-01
2013-04-01
2017-09-01
2016-08-01
Thank you!
Based on the error message you posted, I suspect you are wrong concerning one key item. I suspect that YMDOD is actually a character variable that happens to contain digits, not a numeric variable. A PROC CONTENTS would reveal that. If that's the case, you need a simpler, slightly different solution:
data want;
set have;
ymdod_formatted = input(ymdod, yymmn6.);
format ymdod_formatted yymmdd10.;
run;
Assuming that dod is a numeric variable
data have;
input dod;
datalines;
201705
201304
201709
201608
;
data want;
set have;
dod_formatted=input(put(dod, best6.), yymmn6.);
format dod_formatted yymmdd10.;
run;
dod (should be "ymdod", sorry) is a numeric value. The data I have contains over 11 million cases. New to SAS coding. Is there a way to bypass the first set of code to avoid entering in the raw data using the "datalines" step?
Here is what I did with your code, but it is not working. The error message is below.
data want;
set have;
input ymdod;
ymdod_formatted=input(put(ymdod, best6.), yymmn6.);
format ymdod_formatted yymmdd10.;
run;
ERROR 48-59: The format $BEST was not found or could not be loaded.
Hi @dwhitney ,
Please remove the input statement, since you are using the set statement.
Regards,
Anushree
What is the name of your dataset? Then insert that instead of "have" in the Set Statement. Also, you don't need the Input Statement. I suspect, this will give you what you want
data want;
set have;
ymdod_formatted=input(put(ymdod, best6.), yymmn6.);
format ymdod_formatted yymmdd10.;
run;
Based on the error message you posted, I suspect you are wrong concerning one key item. I suspect that YMDOD is actually a character variable that happens to contain digits, not a numeric variable. A PROC CONTENTS would reveal that. If that's the case, you need a simpler, slightly different solution:
data want;
set have;
ymdod_formatted = input(ymdod, yymmn6.);
format ymdod_formatted yymmdd10.;
run;
You are correct! It was in the character format. Thanks so much! The code worked great!
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.