- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @dwhitney ,
Please remove the input statement, since you are using the set statement.
Regards,
Anushree
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You are correct! It was in the character format. Thanks so much! The code worked great!