BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AMMAN
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

13 REPLIES 13
kiranv_
Rhodochrosite | Level 12

just use mdy function

data IncurredDate;
set work.AngieClaims;
newdate=mdy( Mnth, Date, Year);
format newdate mmddyy10.;
run;
AMMAN
Obsidian | Level 7

Thanks for the recommendation.  I tried that and got this result.  I don't see the combined variable

 

Capture.JPG

kiranv_
Rhodochrosite | Level 12

try making new column name as date and I have updated my answer

AMMAN
Obsidian | Level 7

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;

Capture.JPG

kiranv_
Rhodochrosite | Level 12

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;

 

AMMAN
Obsidian | Level 7

Ooof,  I don't understand your feedback.

 

 

kiranv_
Rhodochrosite | Level 12

did u run the codes. first 2 work if your month, day and year are allowable then mdy code work. 

AMMAN
Obsidian | Level 7

Thanks for your help.  I was looking at the wrong variable. 

andreas_lds
Jade | Level 19

@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.

AMMAN
Obsidian | Level 7

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!

Tom
Super User Tom
Super User

Because you are still trying to use a variable that doesn't exist for the year number.

Tom
Super User Tom
Super User

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.

AMMAN
Obsidian | Level 7

Thanks for your help!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 13 replies
  • 4992 views
  • 0 likes
  • 4 in conversation