BookmarkSubscribeRSS Feed
anil
Calcite | Level 5
Find square root of any positive real number without using any function (like sqrt).
Basic arithmetic operators (addition,subtraction,multiplication & division) are allowed. Use only SAS programming.

Thanks,
Anil
8 REPLIES 8
deleted_user
Not applicable
Homework problem? Or did you make a bet with someone?

Exponentiation is expressed with two multiplication symbols.

So, adjust the exponent value for the power you want to apply.

I seem to recall this was early high school maths.
advoss
Quartz | Level 8
David has an excellent idea. Try:
1 data _null_;
2 sqrt = 2**(-.5);
3 put sqrt;run;

0.7071067812
anil
Calcite | Level 5
Thanks for the solution.
The use of expoenetial is not allowed.

The SAS program should have only addition,subtraction,multiplication and division mathematical operators.
Thanks
Cynthia_sas
SAS Super FREQ
Hi:
Interesting problem. I remember that when my daughter went to Montessori school, they had a way of calculating square roots through some kind of repetitive division method.

Apparently, it's a popular topic out on the math forum:
http://www.nist.gov/dads/HTML/squareRoot.html
http://math.arizona.edu/~kerl/doc/square-root.html
http://en.wikipedia.org/wiki/Square_root
http://mathforum.org/library/drmath/view/52609.html
http://www.bbc.co.uk/dna/h2g2/A827453
http://mathforum.org/library/drmath/view/52610.html
http://mathforum.org/library/drmath/view/51890.html

Once you know the algorithm, it should be fairly simple to code in a data step program...although, it seems a sort of an odd exercise, when ** works quite nicely.

cynthia
anil
Calcite | Level 5
Thanks a lot for your references.

This is a problem which is given to new sas learners to understand ' concept algorithm'.

Even though most of the students have understood algorithm,not a single

experienced SAS programmer could write a SAS program.

This is the reason to post this problem.

Experienced SAS programmers are requested to help.

Thanks in anticipation.

Anil
deleted_user
Not applicable
guess this is like getting an abacus to calculate square roots.
(well how did the ancient greek and egyptian architects and engineers achieve so much without our technology? - I guess they knew how to use their own! )

A long time ago in school we calculated square roots with iterative long-division

Later at university "expansion of series" achieved the mathematical equivalent

Now it's just easier to use the simplest formula

as "an experienced sas programmer" I'm not sure why I should care !


I remain to be persuaded

PeterC
Cynthia_sas
SAS Super FREQ
I can see how it would be a good exercise for a new sas learner. It would help them figure out iterative processing, SAS functions, and the order of operations as well as teaching them how to deal with the situation of 1 square root being calculated vs having a file of numbers for which sq rts needed to be calculated.

My general policy on posting code is that if I have a sample program that can be easily changed to illustrate a point, I will post the code. I read the algorithm and I have a general idea of how to write the program.

But there's no benefit for me to write the program. Part of the learning process, in general is understanding the problem and solving it in concept. Then once you understand the solution in concept, if you have to go a step further and write code, then the best way to LEARN is to try something, try something else, make some progress, make some mistakes, read some documentation, try something and read some more documentation (gee, I need a way to break this number into "chunks" -- let me look at the list of SAS functions), and try something else.

At any rate, this question really is off topic for SAS and clinical trial questions and doesn't really belong in this forum.

cynthia
anil
Calcite | Level 5
Dear All,

Thanks a lot for your replies.

As this is offttopic for SAS and clinical trial questionsI want to clse the issue.

Anil

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 8 replies
  • 1679 views
  • 0 likes
  • 4 in conversation