BookmarkSubscribeRSS Feed
hjjijkkl
Pyrite | Level 9

I need to identify subjects that have been one year since their last visit? How can I do that?

ID Last visit
1 1/4/2019
2 5/23/2020
3 4/8/2020
4 9/12/2018
5 8/17/2019
6 12/5/2019
7 5/4/2020

this is the result I want 

ID Last visit
2 5/23/2020
3 4/8/2020
7 5/4/2020
7 REPLIES 7
PaigeMiller
Diamond | Level 26

Please explain the logic that allows you to derive the result from the input data.

--
Paige Miller
hjjijkkl
Pyrite | Level 9
I want to find subject that has been 1 year from today since their last visit.
todays data - last visit = the difference in days
hjjijkkl
Pyrite | Level 9
todays date - last visit date= the difference in days
ballardw
Super User

How do you identify "subject"? Your example "id" does not seem to be the same "subject".

 

If you have one or more variables that uniquely identify a subject this is very easy but if you cannot show us how to identify a subject then it gets pretty obnoxious.

 

Also, what is the current format for your "last visit" variable? Run proc contents and show us. The dates you show will not appear that way with any of the default SAS date formats so I question whether you are providing data as you have it in a SAS data set.

hjjijkkl
Pyrite | Level 9
the ID represents- one person. the iD is from 1-3000, meaning there are 3000 individual in the data. the date format is in yymmdd10.i have more than one variables
PaigeMiller
Diamond | Level 26

I need to identify subjects that have been one year since their last visit? How can I do that?

@hjjijkkl Do you mean "identify subjects that have been less than one year since their last visit"? That's what your output seems to indicate, but your words don't indicate that. You really need to make your words match your example in order to get the quickest answer and the  best answer. We're really guessing when your words don't match the desired results, and that's not a good way to get answers by making us guess.

 

Does this work for you:

 

data want;
    set have;
    if intck('year',last_visit,today(),'c')>=1 then delete;
run;
--
Paige Miller
Reeza
Super User
proc sql;

create table visit1year as

select *

from have

where last_visit - today() >= 365;

quit;

How do you define a year? What about leap years?

If you're using 365 days the formula above will work. If you need a slightly different data calculation you need to explain what that would be.

 


@hjjijkkl wrote:

I need to identify subjects that have been one year since their last visit? How can I do that?

ID Last visit
1 1/4/2019
2 5/23/2020
3 4/8/2020
4 9/12/2018
5 8/17/2019
6 12/5/2019
7 5/4/2020

this is the result I want 

ID Last visit
2 5/23/2020
3 4/8/2020
7 5/4/2020

 

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 811 views
  • 0 likes
  • 4 in conversation