Help using Base SAS procedures


Not applicable
Posts: 0



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';

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...

Posts: 9,367

Re: IF-THEN Loop

Posted in reply to deleted_user
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:
data Week;
set Day;
IF ("1/01/2001" <= Date <= "7/01/2001") then Week= 'Week1';
...more code...

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):

IF DATE = '01JAN2001'd then ...;
IF DATE = 14976 then ....;

Previous forum postings on the subject of date and date/time variables:胮

Previous forum postings on how to post code with special characters such as < and > (someone already sent you this posting to read on July 12)

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation