Contributor
Posts: 26

# Quiz/ Challenging problem?

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
Not applicable
Posts: 0

## Re: Quiz/ Challenging problem?

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.
Frequent Contributor
Posts: 91

## Re: Quiz/ Challenging problem?

David has an excellent idea. Try:
1 data _null_;
2 sqrt = 2**(-.5);
3 put sqrt;run;

0.7071067812
Contributor
Posts: 26

## Re: Quiz/ Challenging problem?

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
SAS Super FREQ
Posts: 9,329

## Re: Quiz/ Challenging problem?

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://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
Contributor
Posts: 26

## Re: Quiz/ Challenging problem?

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
Not applicable
Posts: 0

## Re: Quiz/ Challenging problem?

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 !

PeterC
SAS Super FREQ
Posts: 9,329

## Re: Quiz/ Challenging problem?

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
Contributor
Posts: 26

## Re: Quiz/ Challenging problem?

Dear All,

Thanks a lot for your replies.

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

Anil
Discussion stats
• 8 replies
• 707 views
• 0 likes
• 4 in conversation