Newbie Question - Is this doable? (Getting data from another dataset)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Newbie Question - Is this doable? (Getting data from another dataset)

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!


Accepted Solutions
Solution
‎06-20-2013 07:54 PM
Super User
Posts: 17,840

Re: Newbie Question - Is this doable? (Getting data from another dataset)

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.

SAS Learning Module: Match merging files in SAS

View solution in original post


All Replies
Solution
‎06-20-2013 07:54 PM
Super User
Posts: 17,840

Re: Newbie Question - Is this doable? (Getting data from another dataset)

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.

SAS Learning Module: Match merging files in SAS

Occasional Contributor
Posts: 7

Re: Newbie Question - Is this doable? (Getting data from another dataset)

Thank you! That worked perfectly!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 195 views
  • 0 likes
  • 2 in conversation