DATA Step, Macro, Functions and more

Date between statement error

Reply
Frequent Contributor
Posts: 80

Date between statement error

I have a data step
Data _null;
Z=-1;
Call symputx ('y' ,z);
Run;
%put &y;
Data _null_;
Length DOWN $10;
X=weekday (today ()&y);
If x=1 then DOW = 'Sunday';
If x=2 then DOW = 'M
If x =3 then DOW = 'Tuesday';

If x=1 then DOW = 'Wednesday';
If x=1 then DOW = 'thursday';

If x=1 then DOW = 'friday';
If x=1 then DOW = 'Saturday ';

Call symput('DOW','DOW');
Run;
%put &DOW;
DATA _NULL_; START_DATE=TODAY ()&Y;
IF WEEKDAY (START_DATE)=1 THEN START_DATE =START_DATE-1;
CALL SYMPUT ('DT', " ' "||PUT (START_DATE,date.)||" '");
Run;
In my andstatenent and al1.start_time = &dt1.

Error log
CLI PREPARE ERROR. TERADATA A CHARACTER STRING FAILED TO CONVERSION TO NUMERIC VALUE. The dt1. Resolves to 30oct16



Super User
Posts: 17,863

Re: Date between statement error

This doesn't make a whole lot of sense. Why multiply the date by -1, that will cause issues down the road. You have multiple checks for day of week 1?

 

 

1. Look at DOWNAME format. 

%let dow=%sysfunc(today(), downame.);
%put &dow.;

2. Where is the error being generated from? You've posted a lot of code - what's the actual issue?

3. I don't see the keyword BETWEEN so not sure what you're referring to here. 

 

Super User
Posts: 17,863

Re: Date between statement error

If you're trying to increment the date use the INTNX function rather than -1 to make sure it evaluates properly. 

Super User
Posts: 10,516

Re: Date between statement error

You have a Teradata error but do no show any connection, so missing some information.

Also putting quotes into macro variables frequently causes issues and your DT varaible has spaces inside the single quotes which may be even more problematic depending on use.

 

I would also suggest use of DATE9. so that you have a 4 digit year just in case year values become an issue. Some other program may assume that 16 is 1916.

Trusted Advisor
Posts: 1,392

Re: Date between statement error

If you don't expect years like 19xx in your data then add to your code:

     options yearcutoff = 2000;

Super User
Posts: 5,257

Re: Date between statement error

You don't show the actual Teradata call, so a bit guessing here.

If you are using implicit pass through (using Libname to Teradata), I assume that you need to use a SAS date literal, you can either extend your macro variable, or add it at macro variable resolution.

 

If you are using explicit pass through, you need a format that Terdata accepts, and chances are that they prefer a ISO date.

Data never sleeps
Ask a Question
Discussion stats
  • 5 replies
  • 326 views
  • 0 likes
  • 5 in conversation