BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
112211
Obsidian | Level 7

 


Data QS_ ;
 do qsdat = '26aug2021'd to '08oct2021'd,"13apr2022"d to "15apr2022"d ;
   patient = "1001015";
 output ;
 end ;
 format qsdat date9.;
run ; 

Data qs ;
 set QS_ ;
   if _n_ in (7,10,15,19,25,29) then delete;
RUN ;


Data SV;
 input visit_start $2-9 visit_end $10-17 start_date$18-27 end_date$ 28-37 ;
 patient = "1001015";
 cards ;
 scr1    week0   02sep2021 05oct2021
 week22  week26  07mar2022 12apr2022
 week48  week52  05sep2022 29sep2022
 week74  week78  13mar2023 12apr2023
 week100 week104 05sep2023 09oct2023
 ;

Considering the above QS and SV data I need help in programming the below conditions
for above-defined SV visits

1) If any calendar days are missing from QSDAT falling between
visit_start and visit_end then populate the flag as "Missing date"

2) If additional records are received outside of the defined VISITS then
flag as "Additional"

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Assuming I understood what you mean.

 


Data QS_ ;
 do qsdat = '26aug2021'd to '08oct2021'd,"13apr2022"d to "15apr2022"d ;
   patient = "1001015";
 output ;
 end ;
 format qsdat date9.;
run ; 

Data qs ;
 set QS_ ;
   if _n_ in (7,10,15,19,25,29) then delete;
RUN ;


Data SV;
 input visit_start $2-9 visit_end $10-17 start_date : date9. end_date  : date9. ;
 patient = "1001015";
 format start_date end_date date9.;
 cards ;
 scr1    week0   02sep2021 05oct2021
 week22  week26  07mar2022 12apr2022
 week48  week52  05sep2022 29sep2022
 week74  week78  13mar2023 12apr2023
 week100 week104 05sep2023 09oct2023
 ;

 data want;
 if _n_=1 then do;
  if 0 then set qs;
  declare hash h(dataset:'qs');
  h.definekey('patient','qsdat');
  h.definedone();
 end;
  set SV;
do _date=start_date to end_date;
   if h.check(key:patient,key:_date) ne 0 then do;
     flag1='Missing date';leave;
   end;
end;

do _date=start_date-365*100 to start_date-1;
   if h.check(key:patient,key:_date) = 0 then do;
     flag2='Additional  ';leave;
   end;
end;
do _date=end_date+1 to end_date+365*100;
   if h.check(key:patient,key:_date) = 0 then do;
     flag2='Additional  ';leave;
   end;
end;
drop _date qsdat;
run;

View solution in original post

7 REPLIES 7
Ksharp
Super User

1) Are you the same person ? Why you both ask the almost same question.

https://communities.sas.com/t5/SAS-Programming/How-to-identify-missing-dates/m-p/934916#M367599

 

2)For you second question(this 'Additional Flag' should belong to current or next obs ?),

I don't understand, can you post an example ?

 


Data QS_ ;
 do qsdat = '26aug2021'd to '08oct2021'd,"13apr2022"d to "15apr2022"d ;
   patient = "1001015";
 output ;
 end ;
 format qsdat date9.;
run ; 

Data qs ;
 set QS_ ;
   if _n_ in (7,10,15,19,25,29) then delete;
RUN ;


Data SV;
 input visit_start $2-9 visit_end $10-17 start_date : date9. end_date  : date9. ;
 patient = "1001015";
 format start_date end_date date9.;
 cards ;
 scr1    week0   02sep2021 05oct2021
 week22  week26  07mar2022 12apr2022
 week48  week52  05sep2022 29sep2022
 week74  week78  13mar2023 12apr2023
 week100 week104 05sep2023 09oct2023
 ;

 data want;
 if _n_=1 then do;
  if 0 then set qs;
  declare hash h(dataset:'qs');
  h.definekey('patient','qsdat');
  h.definedone();
 end;
  set SV;
/*length missing_date $ 2000;*/
do date=start_date to end_date;
  if h.check(key:patient,key:date) ne 0 then do;
   flag='Missing date';
/*   missing_date=catx(',',missing_date,date);*/
  end;
end;
drop date qsdat;
run;
112211
Obsidian | Level 7

Thank you for programming Ksharp. Iam not the same person for above mentioned data (now only iam seeing that data) .
And i need additonal flag(same tab only) same as like missing date .
Date in separate "additional data column" and need flag also required for additional

 

For example before "scr1 "(date:02sep2021)
following dates comes under additional :(26-31aug2021,1,2sep2021)
After "week0 "(date:05oct2021)
following dates  comes under additional : 05-08oct2021,13-5apr2022

Ksharp
Super User

Assuming I understood what you mean.

 


Data QS_ ;
 do qsdat = '26aug2021'd to '08oct2021'd,"13apr2022"d to "15apr2022"d ;
   patient = "1001015";
 output ;
 end ;
 format qsdat date9.;
run ; 

Data qs ;
 set QS_ ;
   if _n_ in (7,10,15,19,25,29) then delete;
RUN ;


Data SV;
 input visit_start $2-9 visit_end $10-17 start_date : date9. end_date  : date9. ;
 patient = "1001015";
 format start_date end_date date9.;
 cards ;
 scr1    week0   02sep2021 05oct2021
 week22  week26  07mar2022 12apr2022
 week48  week52  05sep2022 29sep2022
 week74  week78  13mar2023 12apr2023
 week100 week104 05sep2023 09oct2023
 ;

 data want;
 if _n_=1 then do;
  if 0 then set qs;
  declare hash h(dataset:'qs');
  h.definekey('patient','qsdat');
  h.definedone();
 end;
  set SV;
do _date=start_date to end_date;
   if h.check(key:patient,key:_date) ne 0 then do;
     flag1='Missing date';leave;
   end;
end;

do _date=start_date-365*100 to start_date-1;
   if h.check(key:patient,key:_date) = 0 then do;
     flag2='Additional  ';leave;
   end;
end;
do _date=end_date+1 to end_date+365*100;
   if h.check(key:patient,key:_date) = 0 then do;
     flag2='Additional  ';leave;
   end;
end;
drop _date qsdat;
run;
Quentin
Super User

@112211 wrote:

Thank you for programming Ksharp. Iam not the same person for above mentioned data (now only iam seeing that data) .

Interesting, I was wondering the same thing, since the questions are almost identical.  Is this question from a course you are taking? Seems like there must be some common root cause for two different people asking essentially the same question at the same time.  : ) 

 

By the way, I personally don't think it's a problem to ask for help with homework questions here.  Learning to use resources like communities.sas.com is a key part of becoming a successful SAS programmer (IMHO).  But when a question is a homework question or course work, it's generally a good idea to at least mention that fact.  Often that information will help others understand the question, even accept some of the ambiguity in the question (because it's hard to write a good SAS question).  Also, for helping with homework questions, I'll often ask about what SAS methods you are learning.  If you're learning arrays, it's better to give an array solution than a hash table solution, etc.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
mkeintz
PROC Star

I agree with @Quentin 's suggestion to at least mention you are attempting to understand a homework problem.

 

Help us to help you own the question, not just answer it.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
112211
Obsidian | Level 7
Hello Quentin thanks for response ,
first thing is iam Senior clinical programmer and second thing is regarding my post that is real time problem iam facing that issue (i have framed the sample data by considering my realtime data ) So dont think any other way please.
Any efforts solving the query its really helps me a lot .Thanks in advance
mkeintz
PROC Star

@112211 wrote:
Hello Quentin thanks for response ,
first thing is iam Senior clinical programmer and second thing is regarding my post that is real time problem iam facing that issue (i have framed the sample data by considering my realtime data ) So dont think any other way please.
Any efforts solving the query its really helps me a lot .Thanks in advance

You have one response offered by @Ksharp, but it apparently does not entirely meet your objective.  And he was not entirely sure he complete undertood the tast.

 

Could you please post a working DATA step with the results you expect from your sample input data?  Help us help you.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 964 views
  • 3 likes
  • 4 in conversation