Link to home
Start Free TrialLog in
Avatar of esnkumar
esnkumarFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Help with SAS Date Conversion

I am quite new to base SAS and I have a requirement in which one of the date field (file creation date) is read as EBCDIC numeric data from the mainframe file as shown below.

input  @1 CreatedDt s370ff8.;

Now I need to workout a business date from the CreatedDt. Following is the psuedo logic:

if WEEKEDAY(CreatedDt) = 1 then BizDt = CreatedDt-2;

else if WEEKEDAY(CreatedDt) = 2 then BizDt = CreatedDt-3;

else BizDt = CreatedDt-1;

and final format of BizDt should be YYYYMMDD.

How should I convert CreatedDt to SAS Date to use it with WEEKDAY function? (I hope this needs to be converted to SAS date type for any date operations) and how to format the end result (BizDt) to YYYYMMDD after the calculation?

Any help is much appreciated, thanks.
Avatar of theartfuldazzler
theartfuldazzler
Flag of South Africa image

Hi

ok...wow... this is quite a complex one...

Firstly, you are reading in EBCDIC numeric data - but I'm not sure how that numeric data looks?  The first thing you need to do, is convert this data to SAS data.

A number of programs use a base date, and then show a numeric number as the difference from this date.

For instance, Excel uses 1 Jan 1900 = 1, 2 Jan 1900 = 2 etc.
SAS uses 1 Jan 1960 = 1, 2 Jan 1960 = 2 etc.

If the EBCDIC numeric field you are reading in looks like this, then you may need to add or subtract a certain number of days to get back to SAS date of 1 Jan 1960 = 1.  eg.  to change an Excel date to a SAS date, you would need to subtract 21914 days from the Excel date.

Perhaps show what the EBCDIC date looks like, and then we can help convert into SAS.
Avatar of esnkumar

ASKER

Thanks for your quick response. The value of CreatedDt variable in dataset after reading with the following statement

input  @1 CreatedDt s370ff8.;

looks something like: 20120514 (for 14 May 2012). So this suggests that the dates are just a yyyymmdd format numbers in EBCDIC file, unlike as serial numbers that excel use to represent the dates.

Do I need to convert this CreatedDt variable to SAS date type when I use with WEEKDAY() or does SAS convert this implicitly? Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of theartfuldazzler
theartfuldazzler
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial