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;
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.
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.
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:
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.
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.
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;
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?
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.
This is what is being asked:
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.
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.
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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.