BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I use the code as -

data Week;
set Day;
IF ("1/01/2001"<=Date<="7/01/2001") then 'Week'= 'Week1';
IF ("8/01/2001"<=Date<="14/01/2001") then 'Week' = 'Week2';
IF ("15/01/2001"<=Date<="21/01/2001") then 'Week' = 'Week3';
ELSE IF ("22/01/2001"<=Date<="28/01/2001")then 'Week' = 'Week4';
run;

The date is character in the code .

LOG ERROR 180-322: Statement is not valid or it is used out of proper order.


Kindly suggest where am wrong or any articles that deal with this coding...

Regards,
Mark
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
As I explained in a previous post, when you have syntax constructions like < or > or <= , then you must follow the guidelines laid out in the forum posting to which you were previously referred (on July 12 and shown below)

In that forum posting, it explains that you need to REPLACE < with &lt; in your code or <= with &lt;= or with LE.

Otherwise, your code will get truncated and no one will be able to help you. And, yes, it is sort of a pain to do this extra bit of work to post your code, but if you want folks to help you, it is a courtesy to pay attention to what people post and to show that you understand what they are trying to tell you.

For example, you might have wanted to show us something like this:
[pre]
data Week;
set Day;
IF ("1/01/2001" <= Date <= "7/01/2001") then Week= 'Week1';
...more code...
[/pre]

but if you had <= in your code the < would have messed up the forum posting. (And the reason it didn't mess up my code is that I followed the suggestion in the forum topic on preventing special characters from truncating your posting.)

If, for example, you tried an IF statement like this, there is an automatic problem if DATE is a SAS date variable. SAS expects any comparisons to a DATE variable to be done either as the numeric value or as the DATE7 or DATE9 version of the date like this (showing an equality test...not a "between" test):

[pre]
IF DATE = '01JAN2001'd then ...;
or
IF DATE = 14976 then ....;
[/pre]

Previous forum postings on the subject of date and date/time variables:
http://support.sas.com/forums/message.jspa?messageID=39424#39424
http://support.sas.com/forums/thread.jspa?messageID=33006胮

Previous forum postings on how to post code with special characters such as < and >
http://support.sas.com/forums/thread.jspa?messageID=27609 (someone already sent you this posting to read on July 12)
http://support.sas.com/forums/message.jspa?messageID=39361#39361

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 672 views
  • 0 likes
  • 2 in conversation