DATA Step, Macro, Functions and more

Macro Wrong Date Display

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Macro Wrong Date Display

I am writing the following code to Obtain DTM1 = 03JUN2013:09:15:00.

But Instead it gives me the value of DTM1 =  07JUL****:09:15:00.

 

I am not sure how is it converting 03062013 into 07JULY**** .

 

Plz. Help.

  

%Macro DTX(d);
Data FA.ACC_NBNSFinal; Set FA.ACC_NBNSFinal_&d;
OrdDate = &d; /*'&d'd Gives Error*/
Format OrdDate Date9.;
DTM1=dhms(OrdDate,0,0,T);
format DTM1 datetime22.;
Drop OrdDate;
run;
%Mend;
%DTX(03062013);

 

Thanks in Advance.

 

Ritesh


Accepted Solutions
Solution
‎03-02-2017 02:38 AM
Super User
Posts: 19,870

Re: Macro Wrong Date Display

[ Edited ]
Posted in reply to rkdubey84

SAS is seeing it as a number, specifically the number of days from Jan 1, 1960. 

 

First convert it to a SAS date or pass as a date literal. 

 

%dtx('03Jun2016'd);

 

Or convert it to a date, 

 

ordDafe = input(put(&d, 8.), ddmmyy8.);

 

 

View solution in original post


All Replies
Solution
‎03-02-2017 02:38 AM
Super User
Posts: 19,870

Re: Macro Wrong Date Display

[ Edited ]
Posted in reply to rkdubey84

SAS is seeing it as a number, specifically the number of days from Jan 1, 1960. 

 

First convert it to a SAS date or pass as a date literal. 

 

%dtx('03Jun2016'd);

 

Or convert it to a date, 

 

ordDafe = input(put(&d, 8.), ddmmyy8.);

 

 

Contributor
Posts: 36

Re: Macro Wrong Date Display

OrdDate = input(put(&d, 8.), ddmmyy8.);

Worked the wonders for me.

Thanks a Ton Reeza Smiley Happy
Super User
Posts: 11,343

Re: Macro Wrong Date Display

Posted in reply to rkdubey84

A hint for future diagnosis: the appearance of **** indicates that SAS can't correctly display the value with the chosen format. When you see this in a DATE related context it usually means that the date is past the year 9999. A brief example:

 

data _null_;
   x = '15JAN10350'd;
   year = year(x);
   put x= best12. +1 'with date format'+1 x= date9. year=;
run;

Until someone convinces SAS that we need to display more than 4 digit years none of the existing date/datetime formats will display years after 9999 correctly.

 

Contributor
Posts: 36

Re: Macro Wrong Date Display

@ballardw: Hahahaha... That's quite a proactive thinking for the near future. Smiley Happy
Super User
Posts: 11,343

Re: Macro Wrong Date Display

Posted in reply to rkdubey84

rkdubey84 wrote:
@ballardw: Hahahaha... That's quite a proactive thinking for the near future. Smiley Happy

I was working on some data prior to the year 2000 and kept getting requests about whether the way I was handling data is SAS would be acceptable for Y2K issues. After about a dozen of those I did some tests with SAS date values to find the valid ranges and noted that they end 31 Dec 20000 for date literals: x='31DEC20000'd;

 

The questions stopped when I emphasized that the dates were good for most of the next 18,000 years.

 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 143 views
  • 3 likes
  • 3 in conversation