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

I am trying to create a variable that will indicate if both LDOS and FDOS are :

after span_end_2

and before after_cutoff_2

and before span_end_3. 

The issue I have is that in most cases, span_end_3 is blank/.  in which case the current code I have below will treat LDOS and FDOS as >  span_end_3.  I need to fix my code so sas will treat LDOS and FDOS as < span_end_3 when span_end_3 is blank. Is there a way to do this?

data have;
input
ID$	LDOS :DATE9.	FDOS :DATE9.	Span_Begin_1 :DATE9.	Span_End_1 :DATE9.	Span_Begin_2 :DATE9.
Span_End_2 :DATE9.	Span_Begin_3 :DATE9.	Span_End_3 :DATE9.	after_cutoff_2 :DATE9. ;

format FDOS MMDDYY10. LDOS MMDDYY10. Span_Begin_1 MMDDYY10. Span_End_1 MMDDYY10.  Span_Begin_2 MMDDYY10.
Span_End_2 MMDDYY10. Span_Begin_3  MMDDYY10. after_cutoff_2 MMDDYY10.;

datalines;

5	20Apr2023	20Apr2023	1Jul2022	    29Jul2022	21Nov2022	    4Apr2023	.	  .	    3Apr2024	
5	24Apr2023	24Apr2023	1Jul2022	    29Jul2022	21Nov2022    	4Apr2023	.	  .		3Apr2024	
5	25Apr2023	25Apr2023	1Jul2022	    29Jul2022	21Nov2022	    4Apr2023	.	  .		3Apr2024	
5	1May2023	1May2023	1Jul2022	    29Jul2022	21Nov2022    	4Apr2023	.	  .		3Apr2024	

;;;
run;

data want;
set have;

if LDOS gt Span_end_2 
and FDOS gt Span_end_2  
and LDOS lt after_cutoff_2
and FDOS lt after_cutoff_2 
and LDOS lt Span_end_3 
and FDOS lt Span_end_3 
then After_Span2=1;
else After_Span2=0;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Below is untested, but why not change

 

 

and LDOS lt Span_end_3 
and FDOS lt Span_end_3 

to

  and (span_end_3=. or LDOS lt Span_end_3 )
  and (span_end_3=. or FDOS lt Span_end_3 )

Editted note:

If you have instances of both span_end_3 and LDOS (or FDOS) the above suggestion would still pass the IF test.  If you want such situations to fail the test, then use

 

 

  and LDOS lt max(LDOS,Span_end_3)
  and FDOS lt max(FDOS,Span_end_3)

 

 

This will force both LDOS (or FDOS) and span_end_3 to be non-missing as well as satisfy the desired inequality.

 

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

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

View solution in original post

1 REPLY 1
mkeintz
PROC Star

Below is untested, but why not change

 

 

and LDOS lt Span_end_3 
and FDOS lt Span_end_3 

to

  and (span_end_3=. or LDOS lt Span_end_3 )
  and (span_end_3=. or FDOS lt Span_end_3 )

Editted note:

If you have instances of both span_end_3 and LDOS (or FDOS) the above suggestion would still pass the IF test.  If you want such situations to fail the test, then use

 

 

  and LDOS lt max(LDOS,Span_end_3)
  and FDOS lt max(FDOS,Span_end_3)

 

 

This will force both LDOS (or FDOS) and span_end_3 to be non-missing as well as satisfy the desired inequality.

 

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

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1 reply
  • 624 views
  • 0 likes
  • 2 in conversation