DATA Step, Macro, Functions and more

Date format

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Date format

Here is the below code which i am using and the studystart and end is coming as 01JAN1960 for all.

The input dataset TRTSDT and TRTEDT has both date9. format and numeric. I am not sure why it is converting to 01JAN1960

 

%macro ndtv(StudyStart=TRTSDT,
StudyEnd=TRTEDT
);


data inc;
format STUDY_START STUDY_END date9.;
set adam.adsl;
STUDY_START = datepart(&StudyStart.);
STUDY_END = datepart(&StudyEnd.);
run;

%mend;
%ndtv;


Accepted Solutions
Solution
‎05-30-2017 06:58 AM
Super User
Posts: 5,504

Re: Date format

Posted in reply to alexdsa310

The DATEPART function should only be applied to SAS DATETIME values, not to SAS DATE values.  Evidently, your incoming variables (TRTSDT and TRTEDT) are already SAS dates.  You can simply replace those two lines of your DATA step with:

 

STUDY_START = &StudyStart.;

STUDY_END = &StudyEnd.

View solution in original post


All Replies
Solution
‎05-30-2017 06:58 AM
Super User
Posts: 5,504

Re: Date format

Posted in reply to alexdsa310

The DATEPART function should only be applied to SAS DATETIME values, not to SAS DATE values.  Evidently, your incoming variables (TRTSDT and TRTEDT) are already SAS dates.  You can simply replace those two lines of your DATA step with:

 

STUDY_START = &StudyStart.;

STUDY_END = &StudyEnd.

Super User
Super User
Posts: 7,955

Re: Date format

Posted in reply to alexdsa310

Hi, bit off topic, what is the purpose of this code?  You have ADaM datasets (which are the basis for analysis) with the date variables already present, why the intermediary step to duplicate variables?

TRTSDT indicates a date variable - i.e. doesn't contain timepart, which is why I question the code, as it doesn't actually do anything?

Contributor
Posts: 41

Re: Date format

I am using this for table creation and specifying start date and end date from adsl in macro call for AE tables

Super User
Super User
Posts: 7,955

Re: Date format

Posted in reply to alexdsa310

Yes, but you already have those two variables?  If you have:
TRTSTDT   TRTETDT

01JAN2017 10JAN2017

 

After your code you would have:

TRTSTDT   TRTETDT    STUDY_START   STUDY_END

01JAN2017 10JAN2017  01JAN2017         10JAN2017

 

It just doesn't make sense to me, you would have to explain that extra code in your reviewers guide as well?

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 143 views
  • 0 likes
  • 3 in conversation