BookmarkSubscribeRSS Feed
mar0000
Obsidian | Level 7

 

data want;
set have; 
by ID Date Sport; 
keep ID Type Sport Date EventID Defn; 
day = ifc(FIRST.Date, 'Y', 'N'); 
person = ifc(ID, 'Y', 'N'); 
spo = ifc(FIRST.Sport, 'Y', 'N'); 
if Type in (1,2) then do;
dd = intck('MONTH', lag(Date), Date,'C');
if dd=> 6 of FIRST.ID then Defn = 'Y';
else Defn = 'N'
end;
else if Type in (3,4) then do;
if person='Y' and day='Y' and spo='Y' then Defn='Y'
else Defn = 'N';
end;
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 3 Basketball 20MAR2019 1689 58 2 Tennis 30AUG2017 2157

 

The data above is an example of my data. 

This code is almost working how I want it to, but not yet. INTCK is semi-working, and I'm not sure how to completely get it to work (it will say 'Y' for NOV 2011 and 'Y' for JULY 2013, but 'N' for JUNE 2012. Is there a way to fix this? I also want this to return 'Y' for types 3 and 4 if they're 1 day between each other (January 1st and 2nd) and it isn't doing this. How would I fix these?

 

1 REPLY 1
Shmuel
Garnet | Level 18

In your code is the line

person = ifc(ID, 'Y', 'N');

should be

person = ifc(FIRST.ID, 'Y', 'N');

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 271 views
  • 0 likes
  • 2 in conversation