DATA Step, Macro, Functions and more

lesson 10 (combining data sets)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

lesson 10 (combining data sets)

[ Edited ]

Hi.

I have just finished lesson 10 of sas programming1 and have a doubt with question 8 of its final quiz for this lesson. My answer is b, where as the system marks it wrong and says it is c. can someone explain how?

This is the link to the quiz, for your reference:

 https://support.sas.com/edu/OLTRN/ECPRG193/m421/m421_5_b_quiz.htm

 

 

Thanks in advance

Nidhi


Accepted Solutions
Solution
Monday
Super User
Posts: 19,822

Re: lesson 10 (combining data sets)

Posted in reply to nrmahindru

I don't have to 'think', I tested it. 

 

The key idea is here, not what you think will happen, but what SAS does. Your understanding/expectations are good to have and consider but all that matters is what actually happens. You may want different behaviour but it's good to know when things won't behave as you expect.  I think the key from the documentation is in the details section when it discusses BY group processing.

 

Specify the IN= data set option in parentheses after a SAS data set name in the SET, MERGE, MODIFY, and UPDATE statements only. Values of IN= variables are available to program statements during the DATA step. These variables are not included in the SAS data set that is being created, unless they are assigned to a new variable.
 
When you use IN= with BY-group processing, and when a data set contributes an observation for the current BY group, the IN= value is 1. The value remains as long as that BY group is still being processed and the value is not reset by programming logic.

 

View solution in original post


All Replies
New Contributor
Posts: 3

Re: lesson 10 (combining data sets)

Posted in reply to nrmahindru

The answer is A, and it provides a brief explanation:

"The SAS data sets first and second have a one-to-one matching relationship. Each observation in first matches one and only one observation in second."

Super User
Posts: 19,822

Re: lesson 10 (combining data sets)

Confirmed, the correct answer is marked as A by the SAS application.

Hi.
I have just finished lesson 10 of sas programming1 and have a doubt with question 10 of its final quiz for this lesson. My answer is b, where as the system marks it wrong and says it is c. can someone explain how?
This is the link to the quiz, for your reference:
https://support.sas.com/edu/OLTRN/ECPRG193/m421/m421_5_b_quiz.htm


Thanks in advance
Nidhi
Occasional Contributor
Posts: 6

Re: lesson 10 (combining data sets)

Are you sure you are checking the right question? I am talking about #8 from lesson 10 of sas programming 1 essentials. I checked again it says correct answer is C whereas I am getting B. It is about merging data sets.
Super User
Posts: 19,822

Re: lesson 10 (combining data sets)

Posted in reply to nrmahindru
 

Hi.

I have just finished lesson 10 of sas programming1 and have a doubt with question 10 of its final quiz for this lesson. My answer is b, where as the system marks it wrong and says it is c.

 

 

You said Question 10. 

 


nrmahindru wrote:
Are you sure you are checking the right question? I am talking about #8 from lesson 10 of sas programming 1 essentials. I checked again it says correct answer is C whereas I am getting B. It is about merging data sets.

 

Now it's Question 8.

 

So which one are you looking at? 

Occasional Contributor
Posts: 6

Re: lesson 10 (combining data sets)

Oh I am extremely sorry for this mitsake. I meant lesson 10 and question #8. Sorry again. have edited the same in my original message. Thanks
Super User
Posts: 19,822

Re: lesson 10 (combining data sets)

Posted in reply to nrmahindru

Because the key variable on the BY statement is in both data sets then it's marked as 1 for each. 

 

Remember you can actually run the code and check the answer.

 

Add the following to the data step if you need to see the actual values. 

 

vara = A;
varC = C;

 

 

Occasional Contributor
Posts: 6

Re: lesson 10 (combining data sets)

Hi Reeza, 

 

Thanks for getting back again.

 

I do get your point but when we are talking of the second iteration, does it not take values only from amounts? 

 

let me explain what i am thinking:

1st iteration...both same names so both contribute to the output dataset. hence C=1 and A=1

2nd iteration...not same names but the name on amounts matches the one in PDV already... so only amounts contributes to the output dataset. hence C=0 and A=1.

 

What am I missing here and where am i going wrong.

Really need to clear this.

 

 

Super User
Posts: 19,822

Re: lesson 10 (combining data sets)

Posted in reply to nrmahindru

When all else fails, read the documentation. What does it say regarding IN data set option?

Occasional Contributor
Posts: 6

Re: lesson 10 (combining data sets)

i think i need to read it carefully again. As per my understanding it says what i have stated above. Maybe i need to revisit. 

 

what do you think is the correct answer?

Solution
Monday
Super User
Posts: 19,822

Re: lesson 10 (combining data sets)

Posted in reply to nrmahindru

I don't have to 'think', I tested it. 

 

The key idea is here, not what you think will happen, but what SAS does. Your understanding/expectations are good to have and consider but all that matters is what actually happens. You may want different behaviour but it's good to know when things won't behave as you expect.  I think the key from the documentation is in the details section when it discusses BY group processing.

 

Specify the IN= data set option in parentheses after a SAS data set name in the SET, MERGE, MODIFY, and UPDATE statements only. Values of IN= variables are available to program statements during the DATA step. These variables are not included in the SAS data set that is being created, unless they are assigned to a new variable.
 
When you use IN= with BY-group processing, and when a data set contributes an observation for the current BY group, the IN= value is 1. The value remains as long as that BY group is still being processed and the value is not reset by programming logic.

 

Occasional Contributor
Posts: 6

Re: lesson 10 (combining data sets)

Ok. So the fact that the value of the by group is not being reset is making all the difference here. I do see what is happening, which was definitely different from what i was expecting, but was unable to understand the logic behind it.

 

thanks for your time.

Super User
Posts: 19,822

Re: lesson 10 (combining data sets)

Posted in reply to nrmahindru

I think if you run it you'll see why. Think of it this way, although that first table has a single record it's matched against each in the other table and any corresponding data, in this case the EmpID is also brought across. If it wasn't, the EMPID would be missing which isn't you'd expect either. But consider a situation where you have more than just EMPID. 

 

 

 

☑ This topic is solved.

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

Discussion stats
  • 12 replies
  • 125 views
  • 3 likes
  • 3 in conversation