BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TPayne
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
TPayne, both codes show you using a fixed number 1 as the index in your array not the letter i as indicated.

View solution in original post

9 REPLIES 9
novinosrin
Tourmaline | Level 20

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
Fluorite | Level 6
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.
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
TPayne
Fluorite | Level 6

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
PaigeMiller
Diamond | Level 26

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??

--
Paige Miller
TPayne
Fluorite | Level 6

Hi Paige! that is correct- I just want any dose past date25 to be missing! 

Tom
Super User Tom
Super User

@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.

Reeza
Super User
TPayne, both codes show you using a fixed number 1 as the index in your array not the letter i as indicated.
Shmuel
Garnet | Level 18

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

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!
How to Concatenate Values

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.

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
  • 9 replies
  • 719 views
  • 0 likes
  • 6 in conversation