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;
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.
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.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.