Date: Sun, 30 Apr 2006 15:34:30 -0500
Reply-To: Rob Rohrbough <Rob@ROHRBOUGH-SYSTEMS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Rob Rohrbough <Rob@ROHRBOUGH-SYSTEMS.COM>
Subject: More theoretical data structure optimization
Content-Type: text/plain; charset="us-ascii"
The closest I could come to seeing something about this was a post from Ron
Fehd, the "thrifty-thinking maven", of 2/10/05. I would like to store a
series binary (not trinary or ternary) values for a record in one variable.
I can do this in as little as three bytes numeric or one byte character. I
am working in Windows and will confess to not thinking about other
platforms. I have the following log:
1 data junk;
2 length bool $1;
3 bool = 0;
4 do i = 0 to 2;
5 bool = bor(bool, blshift(1, i));
7 put bool=;
NOTE: Numeric values have been converted to character values at the places
NOTE: Character values have been converted to numeric values at the places
NOTE: The data set WORK.JUNK has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Theoretically, each bit can represent one non-exclusive (independent) flag.
If I allow the variable, "i", to reach 3, I get, "Invalid character data,
15.00". If I define "bool" as numeric, I eliminate the NOTE's. The
absolute miser in me wants to get four on/off values into a single character
rather than three. I don't want to waste one or two extra bytes for
anything less than nine non-exclusive flags by being forced to use a numeric
rather than character variable.
Here are my questions for all you mavens:
1. Is there a way to eliminate the "NOTE"s for a character variable used in
this way? I am a log-purist, too.
2. Is there a way of getting rid of that pesky "invalid data" and still use
all four bits? In practice, I probably would never develop production code
that prints a Boolean variable in this way, but it is nice for debugging.
FWIW, I became ambitious enough to try this after reading, "As an
alternative to the numeric dummy variables discussed previously, you can
choose a character variable with a length of 1 byte to serve the same
purpose.", under the On-line Docs, Base SAS, Operating Environment Specific
Information, SAS Companion for Microsoft Windows, Features of the SAS
Language for Windows, Length and Precision of Variables under Windows,
Character Variables. (Anyone for going back to titles and page numbers?)
While I am going a little beyond what they define as "dummy variables"
(i.e., Boolean), this is so close to working nicely, my curiosity is piqued.
Omaha, NE, USA