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. 

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

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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