date9. format

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

date9. format


I have the following code and I need to have variable d in date9. format. Why is is that d resolves to 04Jun2511? I would expect it to (and need it to) resolve to some date in Mar2014.

%let yyyymm=201403;

data test;

  d=&yyyymm;

format d date9.;

run;


Accepted Solutions
Solution
‎07-17-2014 12:50 PM
Super User
Posts: 10,505

Re: date9. format

The value is being resolved as the number 201403 with when the Display Format date9, , as do all date formats, treat as the number of days since 1 Jan 1960 as day 0. 200,000 plus days translates to over 540 years.

try

%let yyyymm=201403;

data test;

D= input("&yyyymm", yymmn6.); /* to apply an INFORMAT to read the value as a date expressed as year and month*/

format d date9.;

run;


View solution in original post


All Replies
Solution
‎07-17-2014 12:50 PM
Super User
Posts: 10,505

Re: date9. format

The value is being resolved as the number 201403 with when the Display Format date9, , as do all date formats, treat as the number of days since 1 Jan 1960 as day 0. 200,000 plus days translates to over 540 years.

try

%let yyyymm=201403;

data test;

D= input("&yyyymm", yymmn6.); /* to apply an INFORMAT to read the value as a date expressed as year and month*/

format d date9.;

run;


Trusted Advisor
Posts: 1,204

Re: date9. format

201403 is just a number for SAS. Try this to get a date within March

%let yyyymm=201403;

data test;

d=input(put(&yyyymm,$6.),yymmn6.);

format d date9.;

run;

☑ This topic is SOLVED.

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

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