BookmarkSubscribeRSS Feed
mar0000
Obsidian | Level 7
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.

5 REPLIES 5
PGStats
Opal | Level 21

You are missing an equal sign in

 

if Type in (1,2) and FIRST.ID then Defn 'Y'; 
PG
mar0000
Obsidian | Level 7
That part is actually in there, I just typed the whole code. The part that isn't working about the code is that it isn't giving me a 6 month difference between two events
PGStats
Opal | Level 21

The last two statements will set defn to a new value, erasing its value from earlier statements. Probably not what you want.

PG
mar0000
Obsidian | Level 7
Am I able to make the last two statemements work in the first two statements?
ballardw
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 682 views
  • 0 likes
  • 3 in conversation