Contributor
Posts: 23

# Calculating numerical differences from dataset variables that have differing "key" values?

Hello,

I am a novice SAS user.  I am trying to calculate simple numerical differences (current variable value minus prior variable value) for certain variables common to two separate SAS datasets.  However, in this case, the key field values in each dataset that I have to use as a "link" between the two intentionally differ in value.  For example, the key value used in dataset one might be 311320 and it's key value counterpart in the other is 311351.  As a result, the numerical differences calculated have to be based on using the variable values for these differing keys in each dataset (in others words, 311351 values minus 311320 values).  I'm a little stumped and need help.

William

Super User
Posts: 23,663

## Re: Calculating numerical differences from dataset variables that have differing "key" values?

How do you know which records go with which then?

What's the logic behind the matches..

Contributor
Posts: 23

## Re: Calculating numerical differences from dataset variables that have differing "key" values?

I have a crosswalk of these six-digit codes (there are ten pairs of these currently) that show the older code crosswalked to the newer one (such as old code 311320 crosswalked to new code 311351, 311330 to 311352, etc).  Normally, this is not the case with this particular product as difference calculations are simply calculated from matching codes which is a bit easier and more straightforward (311320 to 311320, 311330 to 311330, etc).

However, our program revises these codes once every five years so a situation like the above may come up.

PROC Star
Posts: 8,163

## Re: Calculating numerical differences from dataset variables that have differing "key" values?

Seeing your code and examples of the two datasets would help.  You can easily recode values with a simple combination of it then else statements.

Occasional Contributor
Posts: 14

## Re: Calculating numerical differences from dataset variables that have differing "key" values?

It sounds like you could make a custom format to put your OLD_KEY into your NEW_KEY values.  Then just do a join from the NEW_KEY?  It has to know how to join the records.  I would try to use PROC FORMAT to do it.  If you put it into your new format it will translate the old key to the new.

Discussion stats
• 4 replies
• 196 views
• 0 likes
• 4 in conversation