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

Hello !

 

I try to solve some quizzes. Considering the following data set : 

 

Image15.jpg

if you submit the following code : 

 

data emp(drop=Manager_EMP_ID Salary);
     set emp (keep=Manager_EMP_ID Employee_ID Salary);
     if Manager_Emp_ID=101 and Salary >45000;
     Age = yrdif(DOB,'05Feb2017'd,'Actual'd);
run;

 

Why Employee_ID, Age should be the variables appearing in the emp dataset ? The (keep=) on the lane 2 shouldn't ignore DOB while creating the PDV and so creating an error when reaching the following lane ? 

 

Age = yrdif(DOB,'05Feb2017'd,'Actual'd);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Not sure why I had it in my head that INTCK was being used, YRDIF doesn't have the ACTUAL parameter so that needs to be fixed. It will still return an error because DOB is not in the input data set. Note that the KEEP on the SET statement does not include DOB. 

 

 set emp (keep=Manager_EMP_ID Employee_ID Salary);

Then if you look at the data set option closely, it's a DROP. So you know have:

 

manager_emp_id employee_id salary and AGE/DOB (all missing), and then you drop more variables:

 

data emp(drop=Manager_EMP_ID Salary);

So in the end, you end up with:

employee_id, age and DOB, with only Employee_ID filled in. 

 

This is a really, really bad example IMO. You should try finding a different method of studying, I recommend the Little SAS book which has been edited and used by hundred if not thousands of SAS programmers. 

 

 

 

Screen Shot 2019-01-20 at 8.35.42 PM.png

 

 

 

View solution in original post

6 REPLIES 6
Reeza
Super User

'Actual'd isn't whatever you think it is. What are you expecting from that portion of the code?

 

There is no 'actual', I suspect you want the TODAY() function instead perhaps?

 

 


@Masande wrote:

Hello !

 

I try to solve some quizzes. Considering the following data set : 

 

Image15.jpg

if you submit the following code : 

 

data emp(drop=Manager_EMP_ID Salary);
     set emp (keep=Manager_EMP_ID Employee_ID Salary);
     if Manager_Emp_ID=101 and Salary >45000;
     Age = yrdif(DOB,'05Feb2017'd,'Actual'd);
run;

 

Why Employee_ID, Age should be the variables appearing in the emp dataset ? The (keep=) on the lane 2 shouldn't ignore DOB while creating the PDV and so creating an error when reaching the following lane ? 

 

Age = yrdif(DOB,'05Feb2017'd,'Actual'd);

 

 


 

Masande
Fluorite | Level 6

I simply copied the question from the quiz without any modification. I hadn't even noticed the 'Actual'd thing. I know what Actual does in yrdiff (alias for "act/act") but never met the "+d" version.

So my first question remains, and I can add : "What's "Actual"d ?"

Reeza
Super User

The INTCK formula is wrong. Fix that and you'll likely solve your issues. 

Which quiz are you using? If it's a SAS quiz, it's a good idea to report errors like this. 

 

I have no idea what 'actual'd is or what it's supposed to do in this context. It's wrong. 

 

The reason you're getting this type of behaviour is this:

 

data OUTPUT;
set OUTPUT;

When you you use the same name as the input and output set you often get unexpected behaviour when your code errors out, which is what is happening in this case. Fix the errors in INTCK() FIRST and then see if you still have the same issues. 

 

The INTCK() documentation is here:

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1md4mx2crzfaqn14va8kt7qvfhr.htm...


@Masande wrote:

I simply copied the question from the quiz without any modification. I hadn't even noticed the 'Actual'd thing. I know what Actual does in yrdiff (alias for "act/act") but never met the "+d" version.

So my first question remains, and I can add : "What's "Actual"d ?"


 

Reeza
Super User

Ah...well, it's wrong. Whomever wrote that doesn't seem to understand the INTCK() function at all. 

Reeza
Super User

Not sure why I had it in my head that INTCK was being used, YRDIF doesn't have the ACTUAL parameter so that needs to be fixed. It will still return an error because DOB is not in the input data set. Note that the KEEP on the SET statement does not include DOB. 

 

 set emp (keep=Manager_EMP_ID Employee_ID Salary);

Then if you look at the data set option closely, it's a DROP. So you know have:

 

manager_emp_id employee_id salary and AGE/DOB (all missing), and then you drop more variables:

 

data emp(drop=Manager_EMP_ID Salary);

So in the end, you end up with:

employee_id, age and DOB, with only Employee_ID filled in. 

 

This is a really, really bad example IMO. You should try finding a different method of studying, I recommend the Little SAS book which has been edited and used by hundred if not thousands of SAS programmers. 

 

 

 

Screen Shot 2019-01-20 at 8.35.42 PM.png

 

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1404 views
  • 0 likes
  • 2 in conversation