I need to take three numeric variables, combine into one, then convert to a date. I am using a CATX and am getting a warning I don't understand.
data IncurredDate; set work.AngieClaims; date=input(catx("/", Mnth, Date, Year), mmddyy10); format date mmddyy10; run;
Log and input file attached.
Thanks for your help.
From the picture you posted your MONTH variable is named MNTH, your DAY variable is named DOS and your YEAR variable is named YOS.
So the assignment statement you want would be
date=mdy(mnth,dos,yos);
It looks like you probably ran this code instead
date=mdy(mnth,dos,year);
So SAS created a new variable named YEAR that has all missing values. And also made DATE as missing since you did not provide a year value.
just use mdy function
data IncurredDate;
set work.AngieClaims;
newdate=mdy( Mnth, Date, Year);
format newdate mmddyy10.;
run;
Thanks for the recommendation. I tried that and got this result. I don't see the combined variable
try making new column name as date and I have updated my answer
I dropped some vars to clean it up. New var shows up, but it empty
data IncurredDate (drop=MOS DOS YOS Mnth Date Year) ; set work.AngieClaims; newdate=mdy(Mnth, Date, Year); format newdate mmddyy10.; run;
see the below example . even if you have data in character values this works albite it gives note in log.(first 2 examples work)
unless some of your does not make date, which cause this issue. check the examples in code below
data want;
mnth = 1;
d = 2;
yr =2016;
newdate=mdy(mnth,d,yr);
format newdate mmddyy10.;
run;
data want1;
mnth = "1";
d = "2";
yr ="2016";
newdate=mdy(mnth,d,yr);
format newdate mmddyy10.;
run;
/* this will not work because there is 13 as month and result in . and you have note in
log NOTE: Invalid argument to function MDY(13,2,2016) at line 77 column 9.*/
data want3;
mnth = 13;
d = 2;
yr =2016;
newdate=mdy(mnth,d,yr);
format newdate mmddyy10.;
run;
Ooof, I don't understand your feedback.
did u run the codes. first 2 work if your month, day and year are allowable then mdy code work.
Thanks for your help. I was looking at the wrong variable.
@AMMAN wrote:
Ooof, I don't understand your feedback.
Start with reading the log of your program: are there any notes about missing values? The function mdy need three numbers to create a data, if one is missing the result is missing, too. @kiranv_ tried to point to the most likely cause of having missing values: your data.
I was confused by the labels. I couldn't understand why it said I was missing values. I was looking at the wrong variable. Thanks for your help!
Because you are still trying to use a variable that doesn't exist for the year number.
From the picture you posted your MONTH variable is named MNTH, your DAY variable is named DOS and your YEAR variable is named YOS.
So the assignment statement you want would be
date=mdy(mnth,dos,yos);
It looks like you probably ran this code instead
date=mdy(mnth,dos,year);
So SAS created a new variable named YEAR that has all missing values. And also made DATE as missing since you did not provide a year value.
Thanks for your help!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.