The SAS Output Delivery System and reporting techniques

How to read different format Dates from external file using single input statement

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 88
Accepted Solution

How to read different format Dates from external file using single input statement

Hi All,

i have issue regarding reading date from external file suppose i have veriable name Date in external file name test.csv, and in the date variable i have observation containing dates with verious format like below

date

========

1jan2010

112010

01012010

010110

now i wanted to read this file using single inout statement how can i do that? is there something if else logic we can try in input statement with informat considering the all valid SAS informat for date?

Please let me know how i can do that?

Thanks in Advanced,

Tushar J.


Accepted Solutions
Solution
‎09-25-2012 12:20 PM
PROC Star
Posts: 7,357

Re: How to read different format Dates from external file using single input statement

There is no informat that can correctly guess all possibilities.  e.g. does 112010 represent Nov 20, 2010, Jan 1, 2010, or Nov (1), 2010?  Regardless, the following may do what you want:

data have;

  input date anydtdte.;

  format date date9.;

  cards;

1jan2010

112010

01012010

010110

;

View solution in original post


All Replies
Solution
‎09-25-2012 12:20 PM
PROC Star
Posts: 7,357

Re: How to read different format Dates from external file using single input statement

There is no informat that can correctly guess all possibilities.  e.g. does 112010 represent Nov 20, 2010, Jan 1, 2010, or Nov (1), 2010?  Regardless, the following may do what you want:

data have;

  input date anydtdte.;

  format date date9.;

  cards;

1jan2010

112010

01012010

010110

;

Frequent Contributor
Posts: 88

Re: How to read different format Dates from external file using single input statement

Thanks a lot Arthur for your Answer, i was under impression that this is something i need to work with informat. Or Proc format procedure...

i was just wondering if you explain me how above program is working step by step, like how sas compile it. cause i never heard about anydtdte. format again Thanks a lot. Your program has certainly solved my issue...

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 226 views
  • 0 likes
  • 2 in conversation