Reading date values

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Reading date values

Hi all,

 

I am working with data in SAS using SAS passthrough for oracle. The date that is pulled is in the format yyyymmdd (e.g 20181123) and is numeric. However, I cannot manipulate this using SAS functions (such as the INTCK function) because it is not in a valid sas format or numeric format. Can anyone advice me on how to work with this please? e.g assume you want to create DATEDIFFERENCE variable as in the data step below. How could one do this please?

 

data Required;

date1=20181123;

Datedifference = intck('day',date1,today();

run;

 

Thanks.


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 9,339

Re: Reading date values

Just a very small change:

data required;
  date1=20181123;
  datedifference = intck('day',input(put(date1,8.),yymmdd8.),today());
run;

Numeric format for numeric variable date1 in the put() function.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Super User
Posts: 8,993

Re: Reading date values

Use the code window - its the {i} above post:

data required;
  date1=20181123;
  datedifference = intck('day',input(put(date1,$8.),yymmdd8.),today());
run;

 

 

Solution
2 weeks ago
Super User
Posts: 9,339

Re: Reading date values

Just a very small change:

data required;
  date1=20181123;
  datedifference = intck('day',input(put(date1,8.),yymmdd8.),today());
run;

Numeric format for numeric variable date1 in the put() function.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 9,339

Re: Reading date values

Please mark @RW9's answer as solution, I just added a very small improvement.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 88 views
  • 0 likes
  • 3 in conversation