BookmarkSubscribeRSS Feed
Anotherdream
Quartz | Level 8

Master

Reeza
Super User

Hi Brandon,

That's not what I had in mind. I'd use a control table to set up the criteria's which may be what you were trying to do in the first place.

If your string becomes too long to include in a macro program you can add the "/lrecl=256;" option to your include statement so that it will run as well. Or as long as it needs to be, I'm not sure what the limit is.

ClientID ConditionID Variable Condition ExceptionType

A        1    LoanType    =ARM      Exclude

A        1    LoanAmount   >180    Exclude

Becomes

if ClientID = "A" and loanType="ARM" and LoanAmount>180 then exceptionType="Exclude"

This is used to generate your code, with a unique condition generated by clientID condition so they can be strung together with an AND in the clauses.

Hope that helps at least a little.

Fareeza

RichardinOz
Quartz | Level 8

I was faced with a similar requirement in student enrolment data, where hundreds of exceptions had to be monitored and the list of exceptions potentially could be enlarged from year to year.  I found it best to break the problem down into more manageable chunks, using SQL or datastep code as best fitted the type of exceptions.  Examples:

1. Null data in a field.  A data _null_ step (or a macro) could be used to generate from a list multiple statements of the type

     If missing(abc) then do ; Exceptioncode = 'xyz' ; output ; end ;

    A following datastep could then screen for all null exceptions.  Not suitable for conditions involving multiple nulls.

2. Generic range errors - check for non client specific out of range exceptions using formats created from the exception specifications - useful for identifying values above a maximum, or zero, or negative, or not in a list of specific values.  A data _Null_ step could create a dynamic list of exceptions of the type

     Exceptioncode = Put(abc, xyz.) ; if not missing (Exceptioncode) then output ;

3. More complex conditions - if you have a relatively small number of clients with a relatively large list of specific exceptions it may pay to separate them out using 

     Where client = 'abc' ;

4. Otherwise create the if statements for complex conditions in another data _null_ statement.

I quite like the idea of generating the multiple If statements in an external file and then using %include to process them.  It creates persistent, viewable and auditable lists of conditions that have been applied.

Data Exceptions ;

     Set rdbms.customer_info ;

     %Include "Null_exceptions.txt" ;

     %Include "Range_exceptions.txt" ;

     %Include "Complex_exceptions.txt" ;

     Keep id, exceptioncode, .... ;

Run;

Data ABC_Exceptions ;

     Set rdbms.customer_info (where = (client = 'ABC')) ;

     %Include "ABC_exceptions.txt" ;

     Keep id, exceptioncode, .... ;

Run ;

Proc Append Base = Exceptions

                    Data = ABC_Exceptions

                    ;

Run ;

Richard.

Anotherdream
Quartz | Level 8

Hiya Richard. I agree that I do like the idea of creating the txt files for audit purposes.

In our example we have hundreds (200+) of clients, with thousands of exceptions across clients.

The big problem I have is the unknown... If tomorrow they come and say "all 10,000 exceptions need to have an additional condition to only trigger if Field "XYZ" is equal to "correct".  I could run al 10,000 exceptions and then subset the results by that field bein "correct", or I could have a master If statement that would only run WHEN that field is correct.

Option 2 is the "best" way to do it in my opinion from a coding standpoint, but it becomes very difficult to set up a table structure that will allow for multiple If then statements within the code (also should we really?).  I will continue to play around with the code more to determine if I want to run all exceptions and then sub-set the results, or if I want to try to code them into the IF statements....

Anotherdream
Quartz | Level 8

Master , did my example give enough information for you to elaborate more on the control table method you are referring too?


Please let me know if I can give any further information to allow you to help. I am pretty stuck still on the best way to go about this project design.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 19 replies
  • 1501 views
  • 0 likes
  • 5 in conversation