user2773013
user2773013

Reputation: 3172

SAS date operation within proc sql

I'm very new to SAS, and am trying to modify this piece of code

proc sql;
select a, Current_Date - 2 - b as some_date
from table

Current_Date is a function in sas. I'm trying to replace it with my own date. a and b are column names in a database i'm connecting to. I tried changing Current_Date to '12nov2013'd, but it doesn't seem to work.

I tried:

1.

%let startFrom = '12nov2013'd;
proc sql;
  select a, &startFrom - 2 - b as some_date
from table

this doesn't work.

2.

proc sql;
  select a, input('12nov2013',date9.) - 2 - b as some_date
from table

This doesn't work

How should Ii do this date operation in SAS

3.

proc sql;
  select a, intck('DAY','19nov2015'd,rqo_tran_date_alt) as TranMonth
from table

this also doesn't work

Upvotes: 0

Views: 200

Answers (1)

Joe
Joe

Reputation: 63424

Nothing really wrong with your first example, though it could be improved.

%let startFrom = '12nov2013'd;

data have;
  input a $ b;
  datalines;
Zero 0
Five 5
Ten 10
Hundred 100
;;;;
run;


proc sql;
  select a, &startFrom - 2 - b as some_date format=date9.
  from have;
quit;

Adding the format is pretty helpful usually, though not required. This assumes b is a numeric variable containing a number of days. If it contains anything else, or is character, this won't necessarily give you the correct result.

Upvotes: 1

Related Questions