BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DanielQuay
Quartz | Level 8

Well, I'm afraid I'm back with another easy question, but I am stuck.  Or rather, I haven't gotten this to work in a way that I am happy.

I have three datasets that have been successfully combined, no problems there. The problem is when I am looking at the data, a number of variables were changed over the years the data was gathered.

 

The question is, "how many of the last 12 months were you employed".

In 2007, this variable was titled Months (which was later used for something completely different, at least I figured out how to separate that mess).  Then in 2008 it was changed to PastPay, and then in 2010 it was changed again to EMP_PAY. The data is pretty straightforward, respondents answered 1-12.  So it would look like:

 

2007

Obs1 = 1  

Obs2 = 3  

Obs3 = 9  

Obs3 = 5  

Obs4 = 11

 

2008

Obs1 = 2  

Obs2 = 3  

Obs3 = 8  

Obs3 = 12  

Obs4 = 7

 

2010

Obs1 = 9  

Obs2 = 2  

Obs3 = 4  

Obs3 = 1  

Obs4 = 8

 

I've tried do loops with if/then statements, tried catx, and tried an array but I haven't been able to get them combined.  (largely because I'm still learning SAS).  Sorry, I'm sure I'll have 8 simple answers and feel really dumb here in about 10 minutes but I'm hitting a wall right now.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

COALESCE().

 

Assumptions:

  • the variable is numeric
  • you want them combined into a single variable (never actually stated what you wanted as output).

 

employed_prev12 = coalesce(Months, PastPay, Emp_Pay);

@DanielQuay wrote:

Well, I'm afraid I'm back with another easy question, but I am stuck.  Or rather, I haven't gotten this to work in a way that I am happy.

I have three datasets that have been successfully combined, no problems there. The problem is when I am looking at the data, a number of variables were changed over the years the data was gathered.

 

The question is, "how many of the last 12 months were you employed".

In 2007, this variable was titled Months (which was later used for something completely different, at least I figured out how to separate that mess).  Then in 2008 it was changed to PastPay, and then in 2010 it was changed again to EMP_PAY. The data is pretty straightforward, respondents answered 1-12.  So it would look like:

 

2007

Obs1 = 1  

Obs2 = 3  

Obs3 = 9  

Obs3 = 5  

Obs4 = 11

 

2008

Obs1 = 2  

Obs2 = 3  

Obs3 = 8  

Obs3 = 12  

Obs4 = 7

 

2010

Obs1 = 9  

Obs2 = 2  

Obs3 = 4  

Obs3 = 1  

Obs4 = 8

 

I've tried do loops with if/then statements, tried catx, and tried an array but I haven't been able to get them combined.  (largely because I'm still learning SAS).  Sorry, I'm sure I'll have 8 simple answers and feel really dumb here in about 10 minutes but I'm hitting a wall right now.


 

View solution in original post

2 REPLIES 2
Reeza
Super User

COALESCE().

 

Assumptions:

  • the variable is numeric
  • you want them combined into a single variable (never actually stated what you wanted as output).

 

employed_prev12 = coalesce(Months, PastPay, Emp_Pay);

@DanielQuay wrote:

Well, I'm afraid I'm back with another easy question, but I am stuck.  Or rather, I haven't gotten this to work in a way that I am happy.

I have three datasets that have been successfully combined, no problems there. The problem is when I am looking at the data, a number of variables were changed over the years the data was gathered.

 

The question is, "how many of the last 12 months were you employed".

In 2007, this variable was titled Months (which was later used for something completely different, at least I figured out how to separate that mess).  Then in 2008 it was changed to PastPay, and then in 2010 it was changed again to EMP_PAY. The data is pretty straightforward, respondents answered 1-12.  So it would look like:

 

2007

Obs1 = 1  

Obs2 = 3  

Obs3 = 9  

Obs3 = 5  

Obs4 = 11

 

2008

Obs1 = 2  

Obs2 = 3  

Obs3 = 8  

Obs3 = 12  

Obs4 = 7

 

2010

Obs1 = 9  

Obs2 = 2  

Obs3 = 4  

Obs3 = 1  

Obs4 = 8

 

I've tried do loops with if/then statements, tried catx, and tried an array but I haven't been able to get them combined.  (largely because I'm still learning SAS).  Sorry, I'm sure I'll have 8 simple answers and feel really dumb here in about 10 minutes but I'm hitting a wall right now.


 

DanielQuay
Quartz | Level 8

Thank You again Reeza,

 

And I'm sorry, I promise, I'm trying to learn how to ask questions better.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1351 views
  • 3 likes
  • 2 in conversation