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

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

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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