BookmarkSubscribeRSS Feed
Sharatm9
Fluorite | Level 6

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. 

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Sharatm9
Fluorite | Level 6
Yes pretty difficult. Will go through the paper. I think I did come across the paper earlier. Thank you
Rick_SAS
SAS Super FREQ

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.

Sharatm9
Fluorite | Level 6
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])
Rick_SAS
SAS Super FREQ

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

ballardw
Super User

@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?

Sharatm9
Fluorite | Level 6

It the first 6. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2296 views
  • 6 likes
  • 5 in conversation