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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extra spaces in datalines 2

Status
Not open for further replies.

tharpa

Programmer
Sep 22, 2009
3
US
Suppose your datalines are not quite even, due to extra spaces on some lines. e.g.

01/03/1950 01/03/1960 03Jan1970
05/15/2000 05/15/2002 15May2003
10/10/1998 11/12/2000 25Dec2005

How can you input this?

For example,
Code:
data ThreeDates;
   input COMPBL(Date1)  mmddyy10.
         COMPBL(Date2)   mmddyy10.
         COMPBL(Date3)  date9.;
   Year12 = yrdif(Date1,Date2,'Actual');
	Year23 = round(yrdif(Date2,Date3,'Actual'));

   format Date1 Date2 Date3 date9.;
datalines;
01/03/1950 01/03/1960 03Jan1970
05/15/2000   05/15/2002   15May2003
10/10/1998 11/12/2000    25Dec2005
;
title "Listing of Three DATES";
proc print data=ThreeDates noobs;
run;
does not work.
 
Try to read in the data using position format.
ex
Code:
data ThreeDates;
   infile datalines truncover;
   length datastring $500;
   input datastring  1-500;
   date1=input(scan(datastring,1,' '),mmddyy10.);
   date2=input(scan(datastring,2,' '),mmddyy10.);
   date3=input(scan(datastring,3,' '),date9.);

   Year12 = yrdif(Date1,Date2,'Actual');
   Year23 = round(yrdif(Date2,Date3,'Actual'));

   format Date1 Date2 Date3 date9.;
datalines;
01/03/1950 01/03/1960 03Jan1970
05/15/2000   05/15/2002   15May2003
10/10/1998 11/12/2000    25Dec2005
;
run;
title "Listing of Three DATES";
proc print data=ThreeDates noobs;
run;

Klaz
 
Can you not just use modified list input? (I think it's called that)


Code:
data ThreeDates;
   input Date1  :mmddyy10.
         Date2  :mmddyy10.
         Date3  :date9.;

   Year12 = yrdif(Date1,Date2,'Actual');
   Year23 = round(yrdif(Date2,Date3,'Actual'));

   format Date1 Date2 Date3 date9.;
datalines;
01/03/1950 01/03/1960 03Jan1970
05/15/2000   05/15/2002   15May2003
10/10/1998 11/12/2000    25Dec2005
;
title "Listing of Three DATES";
proc print data=ThreeDates noobs;
run;


Chris...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top