Date: Wed, 23 Dec 1998 10:56:46 -0500
Reply-To: "Mendicino, Tom" <TMendicino@FLEETCC.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: "Mendicino, Tom" <TMendicino@FLEETCC.COM>
Subject: Re: Speaking of Hashing,
you can also simulate a tree structure u sing SAS!
Content-Type: text/plain; charset="iso-8859-1"
Just a personal preference, but I would change the title to:
%let title1 = '4D65727279204368726973746D6173'x;
Thanks for the gift!
-----Original Message-----
From: Kagan, Jerry [mailto:JKagan@US.IMSHEALTH.COM]
Sent: Wednesday, December 23, 1998 9:09 AM
To: SAS-L@UGA.CC.UGA.EDU
Subject: Speaking of Hashing, you can also simulate a tree structure
using SAS!
Greetings,
To continue the thread of hashing and using SAS to implement advanced
programming concepts -- I thought I would share this simple program which
illustrates how to simulate a "Tree Structure" using SAS. You may need to
run this code to understand exactly what it is doing. It should be in
everyone's tool box--comes in handy on occasion.
BTW, I didn't have anything to do with writing this program. It was given
to me years ago by my good friend, Nosrep Yllis A. I'm just passing it on.
Good holidays!
-Jerry
p.s. I'd appreciate any comments or enhancements.
/**************************************************************************
* Program: Tree.SAS *
* Language: SAS 6.12 *
* *
* Purpose: Example of implementing a Tree structure using SAS *
* *
* Author: Nosrep Yllis A. *
* Date: Dec96 *
* *
* Revisions: *
* ddMonyy PID Comments... *
**************************************************************************/
*** Set tree characteristics;
%let title1 = '4D6572727920582D4D6173'x;
%let height = 50;
%let star = &;
%let nodes = @#$%*&;
%let leaves = ^;
%let trunk = V;
%let base = ~;
%let ballPct = .20;
*** Begin tree gen;
title1;
options pagesize = 200;
data _null_;
length line $&height. ball $1.;
file print;
*** Put root;
line = &title1; put line $&height..-c; put;
line = "&star"; put line $&height..-c;
line = '!'; put line $&height..-c;
*** Build tree;
do x = 2 to &height by 2;
line = repeat("&leaves", x);
*** Add nodes randomly;
do y = 2 to &height-2;
if substr(line, y, 1) = "&leaves" then if ranuni(1) LT &ballPct then
do;
ballNum = floor(ranuni(1)/(1/length("&nodes"))+1);
ball = substr("&nodes", ballNum, 1);
line = substr(line,1,y-1)||ball||substr(line,y+1,&height-y);
end;
end;
put line $&height..-c;
end;
*** Build trunk;
do x = 1 to &height/10;
line = repeat("&trunk", &height/10);
put line $&height..-c;
end;
*** Set base;
line = repeat("&base", &height/2);
put line $&height..-c;
run;
---
Jerry Kagan - kaganj01@IMSINT.com
IMS Health
Plymouth Meeting, PA USA
(610) 834-5290