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

I concatenate separate month and year variables into a single month-year variable, but the resulting variable is in a character format. I am trying to convert that into a SAS date variable to be able to calculate intervals with other date variables.

I am successful in the first step, but unable to get the month-year variable into a SAS date format. Below are the error I am getting and the SAS output. Any help would be much appreciated.

  

  Data two;

  set one;

     date=cats(aamn, aayear);

      put date= ;

 

    format date mmyy7.; run; 

                     

ERROR 48-59: The format $MMYYS was not found or could not be loaded.

Obs

date

AAMN

AAYEAR

1

32003

3

2003

2

12003

1

2003

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

or maybe

 

sasdate= mdy(aamn,1,aayear);

format sasdate mmyyd.;

View solution in original post

4 REPLIES 4
Astounding
PROC Star

A month and a year is not enough to convert to a SAS date.  Dates in SAS refer to a specific day.  If you are willing to use the first day of the month, you could use:

 

sasdate = input( cats(aamn, '01', aayear), mmddyy8.);

format sasdate yymmdd10.;

ballardw
Super User

or maybe

 

sasdate= mdy(aamn,1,aayear);

format sasdate mmyyd.;

ama220
Obsidian | Level 7

Thank you, your code worked for me. 

ama220
Obsidian | Level 7

Thanks, your code is great. Because I needed to limit to the month and year, I found the other code more appreciate to my needs. I really appreciate your help. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 690 views
  • 1 like
  • 3 in conversation