DATA Step, Macro, Functions and more

Date Import Assistance

Reply
Occasional Contributor
Posts: 5

Date Import Assistance

I have data with date of births that I am trying to import. Below is the code to import the date:

DATA BIRTHNEW;
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;

INPUT CHILDDOB 55-62 HOSPITAL 73-76 MOMDOB 124-131;

This obviously imports it as a numeric variable, but I have tried:

INPUT CHILDDOB 55-62 Date8. HOSPITAL 73-76 MOMDOB 124-131 Date8.;

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.

Thanks for your help!
Super Contributor
Super Contributor
Posts: 3,174

Re: Date Import Assistance

No need to post in multiple forums - also this is the correct forum, given the topic area. However, I replied in the other forum - see link:

http://support.sas.com/forums/thread.jspa?threadID=11697&tstart=0


Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,868

Re: Date Import Assistance

Hi:
As it explains here:
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001052066.htm
when it says about column input (of the form 1-10, etc):
"You can read standard character and numeric data only. Informats are ignored."

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

cynthia
[pre]
DATA BIRTHNEW;
INFILE datalines;
input @1 name $4.
@6 childdob mmddyy8.
@15 hospital 3.
@19 momdob mmddyy8.;

putlog 'Show Internal Values in Log';
put _all_;
return;
datalines;
alan 6032004 111 11151963
bob 12242005 111 6181967
;
run;

proc print data=birthnew;
title 'Show different formats for mom and child dob';
format childdob mmddyy10. momdob date9.;
run;
[/pre]
Occasional Contributor
Posts: 5

Re: Date Import Assistance

Thanks Scott,
I have successfully coded for separate M D and Y variables below:

INPUT MBC 55-56 DBC 57-58 YBC59-62 DOB_B 55-62;

Now that I have them separated, do I then:

Format ChildDOB = MDY (MBC, DBC, YBC);
SAS Super FREQ
Posts: 8,868

Re: Date Import Assistance

Hi:
If you want to take this approach (using the MDY function) then the syntax would be:
[pre]
childdob = mdy(mbc, dbc, ybc);
format childdob mmddyy10.;
[/pre]

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.

cynthia
Occasional Contributor
Posts: 5

Re: Date Import Assistance

Thank you, Cynthia and Scott! It worked! Sorry for the duplicate post.
Super Contributor
Super Contributor
Posts: 3,174

Re: Date Import Assistance

To the OP:

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.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

mdy function site:sas.com
Ask a Question
Discussion stats
  • 6 replies
  • 162 views
  • 0 likes
  • 3 in conversation