BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

First off, i´m new to SAS but i have some experience with similar areas. In the project i´m currently involved in, i was asked to look into the possibilities to change the hard coded calculations made in different models, to instead be put in a more manageable way in "meta-tables", which then could be easily versioned separately.

My idea was to solve the calculation of for instance the following:

if theInput = 14 then theOutput=0;
if theInput > 90 then theOutput=90;

to be calculated as follows instead:

theOutput = calculateMe('theInput',theInput);
where calculateMe has access to a "meta-table" holding the specific calculation logic for the variable 'theInput' (i.e having information about what to return for various values of theInput), enabling it to return the correct value in a generic way.

Do i make any sense to anyone and if so, does anyone know of any "best practices" for implementing this type of "pattern"? Perhaps this is a basic approach for anyone familiar to SAS or statistical programming but i haven´t found anything (sugi or such) on this subject yet. Thanks in advance!
6 REPLIES 6
Doc_Duke
Rhodochrosite | Level 12
A lot of that can be done using the SAS MACRO language. In addition to the manuals, I'd suggest looking at Rick Aster's book on SAS programming shortcurts and one of the BBU's on SAS macro language that are available in the SAS bookstore.

Doc Muhlbaier
Duke
deleted_user
Not applicable
Thank you for the answer, i will look into the macro language to learn more.

It would however still be interesting to know if there are any best practices for realizing this type of pattern since i have a feeling that it must have been done in various projects before.

Kind regards,
Flip
Fluorite | Level 6
Based on what you are showing, I would create a format using my meta-table as a cntrlin data. then recode based on the format.
Patrick
Opal | Level 21
Hi

If the rules are as simple as in your example then Flip's suggestion sounds good to me.

If the rules are more complex then one way I have seen this done is by storing the rules in a SAS table.
During execution a first data step (data _null_) reads the rules table and creates SAS code which gets 'outputted' to a temporary file. After that use an %include for this temporary file and the generated SAS code will be executed.

SAS macro language is a very powerful addition to Base SAS language. But I strongly recommend that you first get familiar with Base SAS language.

HTH
Patrick
deleted_user
Not applicable
Hi,

Thanks for all the answers - i actually did not think of the solution using formats but that can surely be a good way to realize some of our needs. However, there are, as you mention (but i forgot to), much more complex needs that need a more complex solution and it is here that the "meta table" (not sure this is the right name for it though, hope you know what i mean anyway) comes handy. Using this by importing it in a pre-step before executing the code looks like a good technical/structural solution. The main issue here is that i believe there could/should be a generic way to design such a table which we, in order to prevent reinvention of the wheel, would be really interested in.

Some of the logic (no bore-to-death try attempted) we are looking to solve are for instance also:

if 0 GT (inputOne - inputTwo) LT 1024
then TheOutPut = oneMoreVariable * 1.5;
else if 2048 GT (inputOne - inputTwo) LT 4096
then TheOutPut = oneMoreVariable * 1.66;

which is a more challenging and complex due to the need to represent combinations of expressions in the metadata. This can surely be done, and since there are no rocket science related expressions - rather just simple expressions stacked together, this should be possible to realize in a meta table.

Just a clarification, i am by no means writing here to avoid doing the work myself, i´m just curious if there are any general approaches for dealing with this type of data-driven design since i feel there are a lot of mistakes possible to make when trying to design this table.

Kind regards,
Cynthia_sas
SAS Super FREQ
hi,
Some of what you describe sounds like fairly standard SAS Macro programming and the implementation of business rules sounds like the kind of functionality built into Info Map Studio and Metadata as implemented in the SAS Intelligence Platform (aka the BI Platform). SAS already uses the concept of METADATA in the Platform.

There are many papers about Metadata, as implemented on the Platform. There are probably even more papers written where folks describe their totally awesome SAS Macro applications. Googling around on these search strings should get you started
SAS Metadata BI Platform information maps

SAS Macro application example


Cynthia

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 6 replies
  • 1454 views
  • 0 likes
  • 5 in conversation