BookmarkSubscribeRSS Feed
MichaelM
Calcite | Level 5
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!
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Cynthia_sas
SAS Super FREQ
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]
MichaelM
Calcite | Level 5
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);
Cynthia_sas
SAS Super FREQ
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
MichaelM
Calcite | Level 5
Thank you, Cynthia and Scott! It worked! Sorry for the duplicate post.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1301 views
  • 0 likes
  • 3 in conversation