Hello,
I have a dataset that is pulling in vaccination dates. I want to compare these dates to a specific date and set any vaccination dates to missing if they are after the comparison date. I have the following code, but the dates I would expect to be set to missing are not. Any insight would be helpful.
/*CREATE VARIABLE TO CHECK COMPLETENESS BY 25 MONTH WITH*/
DATA COMPLETE2;
SET ALLVAX3;
DATE25= HS_DOB + 760;
FORMAT DATE25 mmddyy10.;
RUN;
/* SET ANY VACCINATIONS OVER 2YR OLD TO MISSING*/
DATA COMPLETE_DATECHECK (DROP=I);
SET COMPLETE2;
ARRAY DTP(8) DTP1-DTP8;
DO I= 1 TO 8;
IF DTP[1] > DATE25 > . THEN DTP[I]= .;
END;
RUN;
All dates are formatted mmddyy10.
example dataset:
record_id | hs_dob | DTP1 | DTP2 | DTP3 | DTP4 | DTP5 | DTP6 | DTP7 | DTP8 | DATE25 |
224 | 1/5/2016 | 3/31/2016 | 7/18/2016 | 5/2/2017 | 8/8/2018 | 2/3/2018 | ||||
227 | 1/5/2016 | 3/11/2016 | 5/20/2016 | 7/11/2016 | 4/26/2017 | 2/3/2018 | ||||
245 | 1/4/2016 | 3/18/2016 | 5/9/2016 | 7/11/2016 | 4/5/2017 | 2/2/2018 | ||||
254 | 1/5/2016 | 3/4/2016 | 8/2/2016 | 10/5/2016 | 5/11/2018 | 2/3/2018 |
In the above table, I would expect DTP4 for records 224 and 254 to be set to missing.
Thank you!
DATA COMPLETE_DATECHECK (DROP=I);
SET COMPLETE2;
ARRAY DTP(8) DTP1-DTP8;
DO i= 1 TO 8;
IF DTP[i] > DATE25 THEN dtp(i)=.;
END;
RUN;
@TPayne wrote:
I accidentally copied code in to my post from when I was trouble-shooting the issue. My original code is what you have suggested, but that does not produce the expected results either.
Saying it does not produce the expected results does not give enough information.
Show us the data. Show us the actual code you used. Show us the output that isn't what you expect.
Hi Paige!
I edited my post to contain the correct code:
/*CREATE VARIABLE TO CHECK COMPLETENESS BY 25 MONTH WITH*/
DATA COMPLETE2;
SET ALLVAX3;
DATE25= HS_DOB + 760;
FORMAT DATE25 mmddyy10.;
RUN;
/* SET ANY VACCINATIONS OVER 2YR OLD TO MISSING*/
DATA COMPLETE_DATECHECK (DROP=I);
SET COMPLETE2;
ARRAY DTP(8) DTP1-DTP8;
DO I= 1 TO 8;
IF DTP[1] > DATE25 > . THEN DTP[I]= .;
END;
RUN;
For results when I run this, no dates change (i.e. DTP4 for record id 224 and 254 stays the same rather than turning to missing.) The dataset after running the code looks like this:
record_id | hs_dob | DTP1 | DTP2 | DTP3 | DTP4 | DTP5 | DTP6 | DTP7 | DTP8 | DATE25 |
224 | 1/5/2016 | 3/31/2016 | 7/18/2016 | 5/2/2017 | 8/8/2018 | 2/3/2018 | ||||
227 | 1/5/2016 | 3/11/2016 | 5/20/2016 | 7/11/2016 | 4/26/2017 | 2/3/2018 | ||||
245 | 1/4/2016 | 3/18/2016 | 5/9/2016 | 7/11/2016 | 4/5/2017 | 2/2/2018 | ||||
254 | 1/5/2016 | 3/4/2016 | 8/2/2016 | 10/5/2016 | 5/11/2018 | 2/3/2018 |
IF DTP[1] > DATE25 > . THEN DTP[I]= .;
I'm guessing this is the problem, and it should be (not in a DO loop)
if dtp[1]>date25 then call missing(of dtp[*]);
But I don't know if that's the right logic, just to confirm, you are only check if dtp[1] is greater than date25??
Hi Paige! that is correct- I just want any dose past date25 to be missing!
@TPayne wrote:
Hi Paige! that is correct- I just want any dose past date25 to be missing!
Which is not what Paige asked.
Your code is testing if the FIRST date is after the last date.
Sounds like you want to test each date instead.
So use the variable I as the index into the array instead of the number one.
Pay attention to @novinosrin post, the code
IF DTP[1] > DATE25 > ....
1st member in array ???
you probably ment to
IF DTP[i] > DATE25 > ......
the i'th member in array
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: