How do I create a new date variable and specify the value?

Accepted Solution Solved
Reply
Contributor
Posts: 48
Accepted Solution

How do I create a new date variable and specify the value?

Hi,

I would like to create a new date variable called MvmtStartDate and specify that it = 01/01/2007 (mmddyy10. format). Here is my code:

 

data beginningcount;

set combine;

where period=1;

MvmtStartDate=01/01/2007 ;

/*MvmtStartDate= (01/01/2007 - 0);*/

/*MvmtDateStart = '01/01/2007'd;*/

NewMvmtDateEnd = (MvmtDate - 1);

 

format mvmtdatestart mmddyy10. newmvmtdateend mmddyy10.;

run;

 

When I run this (or any of the other options between the /* */), the code either doesn't work, gives me a character value, or sets MvmtStartDate=01/01/1960 (the default SAS start date). I don't want a character value because I want to be able to use the 01/01/2007 date to calculate timing with other dates. The rest of the code appears to work fine. I am sure there must be an easy fix, but I am at a loss. Any help would be much appreciated. Thank you!

 

 


Accepted Solutions
Solution
‎07-07-2016 03:29 PM
Super User
Posts: 10,516

Re: How do I create a new date variable and specify the value?

Date literals, which what you are attempting use as a fixed date you specify are in the 'ddMONyy'd or 'ddMONyyyy'd. No other forms will work.

So instead of

MvmtStartDate=01/01/2007 ;

use

MvmtStartDate= '01JAN2007'd;

 

Also your format statement looks to reference the wrong variable:

format mvmtdatestart mmddyy10. newmvmtdateend mmddyy10.;

which would create another new variable with all missing values.

View solution in original post


All Replies
Respected Advisor
Posts: 4,651

Re: How do I create a new date variable and specify the value?

[ Edited ]

The format for SAS date literals is '01JAN2007'd

 

you can assign your variable any format you want, but literal values only have one format

 

format myDate mmddyy10.;

myDate = '01JAN2007'd;

 

PG
Solution
‎07-07-2016 03:29 PM
Super User
Posts: 10,516

Re: How do I create a new date variable and specify the value?

Date literals, which what you are attempting use as a fixed date you specify are in the 'ddMONyy'd or 'ddMONyyyy'd. No other forms will work.

So instead of

MvmtStartDate=01/01/2007 ;

use

MvmtStartDate= '01JAN2007'd;

 

Also your format statement looks to reference the wrong variable:

format mvmtdatestart mmddyy10. newmvmtdateend mmddyy10.;

which would create another new variable with all missing values.

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 219 views
  • 0 likes
  • 3 in conversation