Re: Efficient Coding!

Fyi, in some cases
[pre]if missing(MATH1) then MATH1=coalesce(MATH2,MATH3);[/pre]
could be useful to you, but wouldn't help here. Note that
[pre]if(Math2=. and Math3~=.) then do;math2=math3; math3=.; end; [/pre]
can be written
[pre]if Math2=. then do;math2=math3; math3=.; end; [/pre]
with the same result. Not that it matters, just fyi again.

Re: Efficient Coding!

Suggest some self-initiated desk-checking for SAS performance, which many times is data-dependent and application-dependent.

For example, using SUBSTR with lead-character test, such as the statement construct IF SUBSTR(,1,..) is much more expensive with iterating a million times than just using the coding technique IF =: instead. And, not so much a concern, when iterating a DATA step execution only a few times.

You can setup a "test scenario" DO / END loop, as demonstrated below to explore cause/effect with various data-scenarios and coding constructs:

Also, for testing code-path for desired / expected results, suggest using the PUTLOG ">DIAG-nn>" / _ALL_; statement, when used tactically to detect SAS variable value conditions at desired points in a DATA step process/flow -- the use of "nn" helps identify each unique processing point, when there are more than one PUTLOG statements being used.