DATA Step, Macro, Functions and more

Changing month-year variable from character to date format

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Changing month-year variable from character to date format

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


Accepted Solutions
Solution
‎05-14-2018 11:20 AM
Super User
Posts: 13,583

Re: Changing month-year variable from character to date format

Posted in reply to Astounding

or maybe

 

sasdate= mdy(aamn,1,aayear);

format sasdate mmyyd.;

View solution in original post


All Replies
Super User
Posts: 6,785

Re: Changing month-year variable from character to date format

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

Solution
‎05-14-2018 11:20 AM
Super User
Posts: 13,583

Re: Changing month-year variable from character to date format

Posted in reply to Astounding

or maybe

 

sasdate= mdy(aamn,1,aayear);

format sasdate mmyyd.;

Occasional Contributor
Posts: 5

Re: Changing month-year variable from character to date format

Thank you, your code worked for me. 

Occasional Contributor
Posts: 5

Re: Changing month-year variable from character to date format

Posted in reply to Astounding

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. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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