I have data with date of births that I am trying to import. Below is the code to import the date:
INFILE B4 END=EOF7 LRECL=1000;
IF EOF7 THEN INFILE B5 END=EOF8 LRECL=1000;
IF EOF8 THEN INFILE B6 END=EOF9 LRECL=1000;
IF EOF9 THEN INFILE B7 END=EOF10 LRECL=1000;
IF EOF10 THEN INFILE B8 END=EOF11 LRECL=1000;
IF EOF11 THEN INFILE B9 END=EOF12 LRECL=1000;
But they do not import into my dataset correctly. I have also tried just leaving the import as just a numeric variable and then changing the format from the ViewTable screen by double-clicking on the variable name and changing the Column Attributes, but I come across the problem that there are not leading zeros in my source data (Ex. 6032004, 2072005, 11072007) so all of the dates are not of the same length.
So, although you are correct that you need an INFORMAT to read the dates, you will have to change your INPUT statement in order to have the date variables read correctly. It should be a big deal. The program below doesn't have your exact layout, but shows the form of input statement you should try. This form of INPUT is called "formatted input" and you can read an introduction about it here: http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001052077.htm
input @1 name $4.
@6 childdob mmddyy8.
@15 hospital 3.
@19 momdob mmddyy8.;
putlog 'Show Internal Values in Log';
alan 6032004 111 11151963
bob 12242005 111 6181967
proc print data=birthnew;
title 'Show different formats for mom and child dob';
format childdob mmddyy10. momdob date9.;
If you want to take this approach (using the MDY function) then the syntax would be:
childdob = mdy(mbc, dbc, ybc);
format childdob mmddyy10.;
The assignment statement converts your 3 separate variables into one SAS date variable, which represents the number of days since Jan 1, 1960. Then the FORMAT statement would instruct SAS what format to use for the display of the date variable.
For future reference, suggest using Google to find SAS support http://support.sas.com/ website DOC and supplemental technical / conference papers which can help you with syntax issues as you learn the SAS language.
Suggested Google advanced search argument, this topic / post: