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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

12 REPLIES 12
cgmoore
Fluorite | Level 6

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."

Reeza
Super User
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
nrmahindru
Calcite | Level 5
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.
Reeza
Super User
 

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? 

nrmahindru
Calcite | Level 5
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
Reeza
Super User

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;

 

 

nrmahindru
Calcite | Level 5

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.

 

 

Reeza
Super User

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

nrmahindru
Calcite | Level 5

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?

Reeza
Super User

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.

 

nrmahindru
Calcite | Level 5

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.

Reeza
Super User

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. 

 

 

 

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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