Importing dates from an ebcdic file into a SAS data set

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Importing dates from an ebcdic file into a SAS data set

Hi

I have an external ebcdic file. On the file there are date values in the format yyyymmdd. In my input step I am reading these using the format s370ff8 and then setting the format to yymmdd8. in my informat step. However SAS is treating the value that has been read in as the number of days since 1960 instead of an actual date in the format mmyydd8.

Is there a way in my import that I can convert the s370ff8 to a date. An extract of my code is below

Data LIB.FILE;

INFORMAT

     Field1       s370fpd5.

     Date1       yymmdd8.;

INPUT  'Filename' recfm=f lrecl=858;

     Field1     s370fpd5.

     Date1     s370ff8.;

Run;


Accepted Solutions
Solution
‎10-19-2012 05:48 AM
Super User
Super User
Posts: 7,039

Re: Importing dates from an ebcdic file into a SAS data set

Sounds like you have successfully read the ebcdic into a numeric variable, but it is not a date.

So you have the number 19,950,801 and you want to treat those 8 digits as if they were YYYYMMDD.

You can use PUT function to convert the number into the 8 digit string and then use the INPUT function to convert that string into a date.

data x;

  x = 19950801 ;

  x = input(put(x,z8.),yymmdd8.);

  format x date9. ;

  put x;

run;

If you have a lot of values of 0 then you might want to use

x = input(put(x,z8.),??yymmdd8.);

to suppress the invalid data messages the INPUT statement will generate.

View solution in original post


All Replies
Super User
Super User
Posts: 7,039

Re: Importing dates from an ebcdic file into a SAS data set

You need a FORMAT statement to tell SAS how to display the data.   You do not need an INFORMAT statement if you are going to include the format to use to read the text file in the INPUT statement.  You also need a INFILE statement to tell it where the data file is.  You also might want to use column pointers (@ nnn) in the INPUT statement to tell it which column in the record to read the first character of the field.

data want ;

  infile  'Filename' recfm=f lrecl=858;

  input

     Field1    s370fpd5.

     Date1     s370ff8.

  ;

  format field1 date1 date9. ;

run;

Contributor
Posts: 20

Re: Importing dates from an ebcdic file into a SAS data set

 

 

Hi Tom

Thanks for the answer.

It still does not correct the issue though.

An example of a date in the file would be 19950801. SAS appears to be using that value as the number of days since 1960 instead of setting the date to 01 Aug 1996.

Dates were the value is 00000000 are being displayed as 01JAN60. Is there a way that I can tell the program that 19950801 is the actual date.

If I am reading the from the dataset I can use something like  input(put(date,z8.),yymmdd8.) and this converts the date correctly. Is there some way I can use that code when reading the external file in to a dataset.

Solution
‎10-19-2012 05:48 AM
Super User
Super User
Posts: 7,039

Re: Importing dates from an ebcdic file into a SAS data set

Sounds like you have successfully read the ebcdic into a numeric variable, but it is not a date.

So you have the number 19,950,801 and you want to treat those 8 digits as if they were YYYYMMDD.

You can use PUT function to convert the number into the 8 digit string and then use the INPUT function to convert that string into a date.

data x;

  x = 19950801 ;

  x = input(put(x,z8.),yymmdd8.);

  format x date9. ;

  put x;

run;

If you have a lot of values of 0 then you might want to use

x = input(put(x,z8.),??yymmdd8.);

to suppress the invalid data messages the INPUT statement will generate.

Contributor
Posts: 20

Re: Importing dates from an ebcdic file into a SAS data set

Hi Tom

I added that after my input statment and and then added the dates in the format statment.

This has corrected the problem

Thank you

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1109 views
  • 3 likes
  • 2 in conversation