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 |
Please explain the logic that allows you to derive the result from the input data.
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.
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;
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.