Reputation: 1
I'm currently just importing the following data from a .txt file.
George Washington 02/22/1732 12/14/1799
John Adams 10/19/1735 07/04/1826
Thomas Jefferson 04/13/1743 07/04/1826
James Madison 03/16/1751 06/28/1836
James Monroe 04/28/1758 07/04/1831
Andrew Jackson 03/15/1767 06/08/1845
John Quincy Adams 07/11/1767 02/23/1848
William Henry Harrison 02/09/1773 04/04/1841
I'm using the following code:
data presidents;
infile "G:\DeadPresidents.txt";
input Name $23. Birth mmddyy10. Death mmddyy10.;
run;
This allows me to read in the Name and Birthdate correctly, but it won't read in the date of Death, because SAS thinks that the space between the two dates is part of the Death variable. If I change
Birth mmddyy10.
to Birth mmddyy11.
it works fine.
Is there any way to have SAS account for the spaces that separate the variables in the txt file? I would like to be able to use mmddyy10 since that's the length of the actual date variable.
Upvotes: 0
Views: 655
Reputation: 51591
You could just move the cursor. Relative motion
input Name $23. Birth mmddyy10. +1 Death mmddyy10.;
or absolute
input Name $23. @24 Birth mmddyy10. @35 Death mmddyy10.;
Or if you know that BIRTH and DEATH are neither all blanks then use modified list mode
input Name $23. Birth :mmddyy10. Death :mmddyy10.;
Note that if you assign an INFORMAT to the variable and use list mode input then you do not need to specify the width of the informat since SAS will ignore it anyway and adjust the width it uses to the data on the line.
input Name $1-23 Birth Death ;
informat birth death mmddyy. ;
Upvotes: 3