BookmarkSubscribeRSS Feed
Raj_madhavan
Fluorite | Level 6

Hello I have this question I'm facing I have managed to write programme for it but not sure whether it is correct. Please help me to guide through this.

 

I have a data set as follows

 

salary            year

257891.58    2015

 

Question 1

the question is increase the salary variable by 5.65% annually unitll it is greater than $500,000.

Question 2

Increment the year variable by 1 with each annual increase

Question 3

Create an output data set that has one observation for each value of year.Each observation should have a year and salary variable.

 

I have written the following programme I'm i correct ?

 

data results.output12;
set cert.input12;
salary=salary;
do until(salary gt 500000);
salary+salary*0.0565;
year+1;
output;
end;
run;

 

12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Communities 🙂

 

Do you get the results you expected? And if not, what differs to what you expect?

 

Do you see any errors in the log?

 

 

Nothing wrong with the code indeed.

Raj_madhavan
Fluorite | Level 6

Hello Dray thank you for your response , I'm a beginner so practising for exam purpose. I do not know the answers for the questions mentioned in my post.

I have just wrote the programme it has got executed and there were no errors in the log . I was wondering weather that was the right way to write the programme to achieve correct answers for the questions. If possible kindly provide me the answer for the questions so I can compare them with my results.

Astounding
PROC Star

Your program contains many good pieces.  Here are some thoughts to consider.

 

This statement accomplishes nothing and should be removed:

salary = salary;

Your final output does not contain an observation with the original values (salary=257891.53 and year=2015).  You should probably add an OUTPUT statement before the DO loop begins.

 

What if your data set contains observations with questionable data for SALARY:

 

  • negative numbers
  • missing values
  • values that are already over $500,000
  • very small values such as a starting annual salary of $1

In the case of negative numbers or missing values, your DO loop never ends.

 

In the case of large salaries (over $500,000) the DO loop should not execute for that observation.

 

For an original salary of $1 (and some CEOs do take such a salary), do you want to output hundreds of observations in your new data set?

 

At a minimum, handle the first three bullet points.  Here is one way:

if (0 < salary < 500000) then do until(salary gt 500000);

Consider whether you would want to raise the lower limit of 0 to avoid generating many new observations.

 

Raj_madhavan
Fluorite | Level 6

Hello there Thank you for ypur response and  you are absolutely spot on and I completely agree with your points .I will make the amendments as suggested .I'm a beginner/new comer to SAS and I'm practising for exam purpose .  If possible kindly provide me the answer for the questions I posted in my earlier post so I can compare them with my results. 

Astounding
PROC Star

My responses would be relatively simple to add to your program.  This would be the minimum number of changes:

 

* What you have now;

data results.output12;
set cert.input12;
salary=salary;
do until(salary gt 500000);
salary+salary*0.0565;
year+1;
output;
end;
run;

* What I would suggest (at a minimum, possibly change the lower limit of 0);

data results.output12;
set cert.input12;
output;
if (0 < salary < 500000) then do until(salary gt 500000);
   salary+salary*0.0565;
   year+1;
   output;
end;
run;
Tom
Super User Tom
Super User

One skill needed for this type of question (and most exams) is the ability to recognize where what the question is asking is ambiguous.  In that case you need state in clear terms how you are interpreting the question and then provide your answer for this more clearly worded question.

Question 1

the question is increase the salary variable by 5.65% annually until it is greater than $500,000.

Question 2

Increment the year variable by 1 with each annual increase

Question 3

Create an output data set that has one observation for each value of year.Each observation should have a year and salary variable.

They are not explaining exactly what output they want.  Do they want the original year included?  Do they want the year where the value exceeds 500,000 included? What about when salary is exactly 500,000, should it stop then or generate one more year?   Is the increment 5.65% of the first year's value or 5.65% of the new incremented salary (is the increase compounding or not). Also what about when salary starts as missing? Or zero? Or negative?  What about small values of salary?  Is there a maximum number of years to output?  

 

Assuming that they want the first year and then compounded increases of 5.65% over the previous years value you might do something like to insure that output has at least one and at most 101 observations output for every observation in the original dataset.

data have;
  id+1;
  input salary year ;
cards;
0 2019
500000 2010
257891.58    2015
;

data want;
  set have;
  do year=year to year+100 ;
     output;
     if salary <= 0 or salary > 500000 then leave;
     salary+salary*0.0565 ;
  end;
run;

proc print;
run;
Obs    id       salary    year

  1     1         0.00    2019
  2     2    500000.00    2010
  3     2    528250.00    2011
  4     3    257891.58    2015
  5     3    272462.45    2016
  6     3    287856.58    2017
  7     3    304120.48    2018
  8     3    321303.29    2019
  9     3    339456.92    2020
 10     3    358636.24    2021
 11     3    378899.19    2022
 12     3    400306.99    2023
 13     3    422924.34    2024
 14     3    446819.56    2025
 15     3    472064.87    2026
 16     3    498736.53    2027
 17     3    526915.14    2028

Also should the value of salary for each year be rounded to 2 decimal places? Or perhaps to some other level of precision, like a multiple of 1 or 100 or 1,000?  If the value is rounded should values be rounded UP or rounded DOWN?

 

ileniaparente
Fluorite | Level 6
About these values that you obtained, one of the question about this project asks in what year the above value of salary occurs. The solution given is 2027 and because of that my response 2028 was incorrect. Yet, I’m still trying to understand why is that. If the condition specified in the DO UNTIL statement is checked at the bottom of each iteration of the loop, it seems reasonable to me that with an explicit ouput within the DO LOOP the first above value of salary with its corresponding year of occurrence is being written to the output table before exiting the loop once checked the condition. So why exactly would it be true to say that the first above value for salary occurs in 2027?
Tom
Super User Tom
Super User

Sounds like another case where there is an unexplained additional condition or constraint.

 

To me the most obvious reason they would stop one year early would be they expect the percentage increase to be applied in the first year.  So move the code that increases the salary to before the output statement.

ileniaparente
Fluorite | Level 6

This is what is being asked:

Schermata 2021-06-30 alle 15.24.12.png

and the program I wrote to answer the question about the above value of salary with 2028 as the last year being written to the output table:

data results.output12;
	set cert.input12;
	do until (Salary>500000);
		Salary+(Salary*0.0565);
		Year+1;
		output;
	end;
run;

As you said, if I run instead:

data results.output12;
	set cert.input12;
	do until (Salary>500000);
		Salary+(Salary*0.0565);
		output;
		Year+1;
	end;
run;

the last year written to the output table is 2027. Is that what you mean, right?

Maybe, being a native Italian speaker, I did not properly understand what is required. Is there an essential part in how the requested steps are formulated that clears out the fact that Year should be increased by one only after the salary has already been increased by 5.65% within the one and only value of year available in the source data set? I feel like the order of the steps as they are requested does not help at all. Plus, as you said, there is no context explanation so it would be quite a matter of luck to get the whole thing right just by intuition. Just my opinion.

Tom
Super User Tom
Super User

There is nothing in the posted question that helps clarify that question.

 

So in testing situation where you are allowed to provide text you should state how you have decided to answer that ambiguity so that the grader knows that your code is doing what you intended.   If you are only allowed to post code then include the clarification in your comments.

ileniaparente
Fluorite | Level 6
Right, thanks!
pdhokriya
Pyrite | Level 9

You can use this code for your practice:

 

data results.output12;
set cert.input12;
do until(salary gt 500000);
salary +(salary * 0.0565);
output;
year +1;
end;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 12 replies
  • 7823 views
  • 8 likes
  • 6 in conversation