Monatsarchiv für November 2010

 
 

Blogging SAS

Almost at the same time, there are two SAS blogs aggregators popping up to the web for SAS programmers worldwide, one in Chinese, the other, English:

http://saslist.com/  in Chinese, maintained by sxlion, also the owner of a SAS information site,  http://saslist.net/

http://sas-x.com/   in English, maintained by Tal Galili, also the owner of R blogs aggregator, http://r-bloggers.com/

I try to express in a very symmetrical way. What’s more (and interesting), these two aggregators share a same WordPress template. My blogs, in Chinese and in English, are also the members of these aggregators respectively.

I view this is the first wave for SAS programmers to embrace the Web2.0 world. If interested, you could also add your SAS blogs in

http://sas-x.com/add-your-blog/

Recursion: Biblical Evidences

                    

             To Iterate is Human, to Recurse, Divine. 

      –by L. Peter Deutsch, creator of Ghostscript. (I also love his saying “The best thing about a Boolean is even if you are wrong, you are only off by a bit”)

I learned this quote from Tony Barr, designer and developer of SAS (the Statistical Analysis System).  He also used the Recursive Descent method to develop SAS complier. Now Tony is working for AMOR (A Model of Reality). AMOR is the self-defining system for modeling ideas and concepts (or human knowledge).—Recurse again: in AMOR, the type is defined by the type of type, and, the type of type is also defined by the type of type of type . . .

To help to understand the DIVINE part of recursion, Tony gave two examples from the Bible:

1. The Golden Rule is recursive.

Do unto others as you would have them do unto you. (see Matthew 7:12, or Luke 6:31)

2. God indentify himself in a recursive way.

Moses asked God for his name. Then God said to Moses, “I AM THAT I AM.” (see Exodus 3.14)

I’d like add two items (from a programmer’s perspective rather than Biblical Theology):

3. Recursion at the very start

In the beginning was the Word, and the Word was with God, and the Word was God. (see John 1.1; also see here)

4. The Trinity recursive way

First, there is only one God in Christian doctrine. God the Son duplicates the nature of God the Father in every way exactly, and so God the Spirit. And what’s about God the Father? see above.

Power of Logic Operators: a trick

Suppose you should group people based on their ages as follows:

ID Age agegrp
001 1 1
002 4 2
003 5 2
004 5 2
005 2 1
006 4 2
007 5 2
008 2 1
009 9 3
010 8 3

and the rules:

age<4,           group 1

4<=age<6,     group 2

6<=age<10,  group 3

It is a very simple question and you could use the if/else statement without thinking:

data age;
input ID $ age;
datalines;
001 1
002 4
003 5
004 5
005 2
006 4
007 5
008 2
009 9
010 8
;

data age1;
set age;
if age<4   then agegrp=1;
else if age<6   then agegrp=2;
else agegrp=3;
run;
proc print;run;

or, you could use proc format to map data:

proc format;
value agegrp
low-<4=”1″
4-<7  =”2″
7-<10 =”3″
other =”"
;
run;

data age2;
set age;
agegrp2=put(age,agegrp1.);
run;
proc print;run;

And try to use logic operators. It is a ONE-LINE-OF-CODE approach:

data age3;
set age;
agegrp3=1+(age>3)+(age>5);
run;
proc print;run;

In SAS, a logic express returns to 1 or 0 according the true of false of the express. The logic behind the above statement is:

  • age group is set to 1 at the beginning;
  • if age>3, age group adds 1;
  • if age>5, add 1.

This easy-to-follow logic can apply to other scenarios(flags, for example):

flag=value>50;

select value>50 as flag    (in proc sql)

Recursive Referencing and Binomial Proportion Interval

To understand recursion, one of the most important concepts in programming languages, you could watch the movie, Chris Nolan’s Inception: it is about a dream within a dream within a dream, …and, read two statistical papers by Professor Robert Newcombe, one of the most prolific statisticians:

These two widely cited papers evaluate 7 and 11 methods to calculate single proportion (paper A) and the difference between proportions (paper B), respectively. Further more, they were in the same issue of Statistics in Medicine(Volume 17, 1998), and, they were also cross referenced! So here is a live story about recursive referencing(thanks to Prof. Newcombe):

megamonalisa_recursion

    • An author writes two papers, A and B;
    • Paper B is in the  bibliographic reference session of paper A;
    • Paper A is also in the  bibliographic reference session of paper B;
    • Paper A and paper B are in the same issue of a journal.

Note that for Prof. Newcombe’s two linked papers, it is common and acceptable in publication practices. Recently I used these two wonderful papers to learn CI calculation and this post just want to lead to the concept of “recursion”  (reference in reference in reference).