Can someone please help me answer this question.
Write code in SAS that allows one to write to a csv file a data set with all natural numbers less than a given parameter N as well as a boolean variable indicating if the number is perfect or not.
So the CSV must contain
1, False
2, False
6 True
Im a first time SAS user and I cant seem to go anywhere with this.
Seems like a very difficult problem for a first-time user.
This paper can help: https://support.sas.com/resources/papers/proceedings15/3384-2015.pdf
You might want to recheck the statement of the problem. A common programming assignment is to determine whether a number is a perfect square. That only requires checking whether
ceil(sqrt(x))**2 = x
This is much easier than determining whether a number is perfect, which is an abstract property in number theory.
Okay. I don't know if your class discussed PROC FCMP, which enables you to define DATA step functions. If so, I recommend that you write an FCMP function that takes a number and computes whether it is perfect by finding the sum of all integer divisors. A short intro to PROC FCMP is at "Extending SAS: How to define new functions in PROC FCMP."
@Sharatm9 wrote:
Thank you for response, Sir. But the question is correct. It requires us to get first N (6) perfect numbers. (where the divisors adds upto to the number. the quoted example is 28[1,2,4,7,14])
Finding the first 6 of just about anything is likely to be much easier than an arbitrary N as indicated in your first post. So which is it, first 6 or first N?
It the first 6.
Given the limitations of SAS, only the first 7 perfect numbers can be calculated with numeric variables anyway (see https://en.wikipedia.org/wiki/Perfect_number and the continuing link https://oeis.org/A000396).
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.