Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't readin dates?

Status
Not open for further replies.

saqi2000

Programmer
Apr 11, 2002
84
GB
Hi guys,

I have got a txt file and it has got some dates in it in the following format (ddmmyy8.):
12/12/71

but when I try to read in using below data step it does not read in and it inserts period (.) instead of date (this happens when I try to read it in as a numeric) but it reads fine as a character.

Is it possible to readin dates?

Data work.line;
infile "c:\temp\upload.txt";
input id 1-5 lineno 7-9 emp 11-19 dob $ 21-28
fname $ 30-88 type 90-92 comp_id 94-98
valid 101-105 product $ 107 absind $ 109
ptake $ 111-115 tot 117-119 est $ 121-123
desig $ 125-127 sigs $ 129-131 prdevid $ 133
prdscrip $ 135 prdfeed $ 137 prd_status 139-141
date_stocked $ 143-150 lockstat 152-154
date_stamp $ 156-174;
run;


text file:

12345,123,123456789,26/12/71,My Name is Saqi The Angel I work for Harvard College of Com,123,456789,12345,N,Y,Mondy,100,Yes,Tes,Nop,M,N,O,444,26/12/71,999, 11NOV02:13:56:05


Thanks

Saqi Knowledge is something no one can steal from you and it increase as time goes by. Saqi
 
Hi Saqi,

using formats is right - you can either read in as text, then make it a numeric date (see below), or use an informat on reading.

Code:
69   data _null_;
70      dt = '12/12/71';
71      numdt = input (dt, DDMMYY8.);
72      put numdt 'is ' numdt DATE9.;
73      run;

4363 is 12DEC1971
NOTE: DATA statement used:
      real time           0.02 seconds
      cpu time            0.02 seconds

Cheers,
Matthias
 
Matthias,

thanks for your help. I have got it working using formats.

Cheers

Saqi Knowledge is something no one can steal from you and it increase as time goes by. Saqi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top