Hi there,
I've only been using sas for about 18 months, and mainly easy stuff. I'm just now venturing into the macro world.
That said, I am trying to figure out how to do something. I've tried several things but I can't seem to figure out the best approach.
I have two datasets, one I'll call "People" and one I'll call "Dates". The people dataset is a listing of, you guessed it, a lot of people and their information. The dates dataset contains a listing of contract periods (effective and end date) that their employer has agreed to. My goal is to identify the correct contract period when the person turned (or will turn) a specific age (19). My problem is that some people were 19 before the earliest contract, so it wouldn't exist (I need to default to the earliest in that situation) and some people won't be 19 for a few years (so I need to default to the highest in that situation).
In Visual Basic, this would be easy. I would create a function to take the person's 19th birthday (already got this down), then loop through each contract until I find the one that would encompass the birthday and return the contract's end date to the calling subroutine, then I can do the rest of my calculations based on that.
I've tried writing a macro in SAS but I always seem to run into errors. Been stuck on this for a few days. I hope somebody here might point me in the right direction?
Thanks!
The process is similar in SAS, you don't need a macro you need a merge and then you check each line to see if it meets your criteria.
If you want code as an example you need to provide data as an example.
One option:
1. Calculate persons 19 year bday
2. Merge via data step
3. As you merge, loop through and check the criteria. Easier to take first/last this way.
The process is similar in SAS, you don't need a macro you need a merge and then you check each line to see if it meets your criteria.
If you want code as an example you need to provide data as an example.
One option:
1. Calculate persons 19 year bday
2. Merge via data step
3. As you merge, loop through and check the criteria. Easier to take first/last this way.
Thank you! That worked perfectly!
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.
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.