data want;
set have;
by ID Date Sport;
keep ID Type Sport Date EventID Defn;
dd = 0<=intck('MONTH', lag(Date), Date) <6;
if Type in (1,2) and FIRST.ID then Defn 'Y';
else if Type in (1,2) and dd < 6 then Defn = 'N';
day = ifc(FIRST.Date, 'Y', 'N');
person = ifc(ID, 'Y', 'N');
spo = ifc(FIRST.Sport, 'Y', 'N');
if person = 'Y' and day = 'Y' and spo = 'Y' then Defn = 'Y'; else Defn = 'N';
run;
data have;
ID Type Sport Date EventID;
12 1 Baseball 06JUN2018 8779
12 1 Baseball 20JUN2019 8452
29 4 Skiing 12JAN2018 5683
29 4 Snowboard 12JAN2018 5683
08 2 Basketball 20MAR2019 1689
58 3 Tennis 30AUG2017 2157
Above is the code and an example of the data. The blue part of the code isn't working properly. I'm not sure how to fix this.
You are missing an equal sign in
if Type in (1,2) and FIRST.ID then Defn 'Y';
The last two statements will set defn to a new value, erasing its value from earlier statements. Probably not what you want.
Example starting data and what you expect the result to be.
Since you have two sets of code setting the same variable to a value then you would need to restructure all of that into a single block of if/then/else. If one part of the code needs multiple statements then enclose the group inside a DO/End block:
else if <some condition> then do;
statement;
statement;
statement;
end;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: