0
votes

I have two lines of data,

Order 17/01/2016 01/02/2014

Basically I want to run a logic like so;

data A.test_active;
set A.Weekly_Email_files_cleaned4;

length active :8.;
length inactive :8.;
if first.Order between '01Jan2014'd and '31Dec2015'd then active= 1;
if last.order between '01Jan2014'd and '31Dec2015'd then inactive= 1;

run;

the field "Order" is formatted by DDMMYY10 when I checked the file properties, but I keep getting this error ERROR 388-185: Expecting an arithmetic operator.

Can anyone help or suggest something different in the same vain?

2

2 Answers

2
votes

In SAS, between is only valid in SQL contexts: either actual PROC SQL, or WHERE statements, generally. It is not otherwise valid in SAS. You would use in (firstval:lastval) instead, if those values are integers (dates are). If they're not integers, you need to use if firstval le val le lastval or similar (can also use ge/lt/gt/>/< or whatever you like, depending on the ordering of things).

Second, first.order and last.order are boolean values - 1 or 0, nothing else, that indicate that you are on a row that is the first row for a new value when sorted by that variable, or the last row similarly. You also must have a by statement by that variable if you're going to use them.

Third, your length statements are wrong; you're confusing some three different things here, I think. Length statements for numerics aren't needed if you're using default length 8, and if you do like having them anyway, you need:

length active 8;

No : or ., both are used for different purposes.

0
votes
 ID     first_order      Order
 alex      01/01/2013     23/01/2015
 alex      01/01/2013     23/01/2015 
 alex      01/01/2013      03/04/2013

basically if an order exists after the first order that is within a certain timeframe (within a year of the date of the first order) then the user is "active"

any ideas much appreciated thanks