Help using Base SAS procedures

How do I turn ddMMMyyyy into one day prior?

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How do I turn ddMMMyyyy into one day prior?

I have a table with a column containing Effective Dates in DDMMMYYYY format.  Expiration Date values don't exist on the table so I need to create my own values for 'Expiration Date'.  I need to Select (EFFECTIVE_DATE - 1 as EXPR_DATE) essentially so that if the Effective Date reads 02APR2011 the new field EXPR_DT will show 01APR2011.

Can anyone help me please?


Accepted Solutions
Solution
‎08-09-2011 04:48 PM
PROC Star
Posts: 7,469

How do I turn ddMMMyyyy into one day prior?

If you are doing it in proc sql you already have the correct syntax if you leave off the parentheses.

A SAS date - 1 is equal to the SAS date of the prior day.  Thus, in a datastep, EXPR_DATE=EFFECTIVE_DATE - 1; would work.

View solution in original post


All Replies
Solution
‎08-09-2011 04:48 PM
PROC Star
Posts: 7,469

How do I turn ddMMMyyyy into one day prior?

If you are doing it in proc sql you already have the correct syntax if you leave off the parentheses.

A SAS date - 1 is equal to the SAS date of the prior day.  Thus, in a datastep, EXPR_DATE=EFFECTIVE_DATE - 1; would work.

New Contributor
Posts: 2

How do I turn ddMMMyyyy into one day prior?

awesome.  hadn't even bother trying a proc yet.  Thanks a bunch.

Trusted Advisor
Posts: 2,115

How do I turn ddMMMyyyy into one day prior?

SAS stores dates internally as the number of days from 1/1/1960, so date arithmetic is simple.  If effective_date is a SAS date, then

expr_dt = effective_date-1;

FORMAT expr_dt date9.;

should do it.  If effective_date is a character string, then you need to first convert it to a SAS date using the INPUT function, like

effective_date_new= INPUT(effective_date, anydate9.);

Doc Muhlbaier

Duke

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 174 views
  • 2 likes
  • 3 in conversation