Date: Thu, 7 Jul 2011 17:14:48 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: alpha-numeric data split into two tables?
Content-Type: text/plain; charset=ISO-8859-1
Assuming the dataset 'old_data' has some variable "datavar", which either
has numeric data in it or 'comment' data in it:
@1 datavar $CHAR20.;
data text_data num_data;
if anyalpha(datavar) then output text_data;
else output num_data;
The ANYALPHA function returns 1 (true) when any alphabetic character is
found, or FALSE if no alphabetic characters are found. This will work if
you explicitly expect alphabetic characters in the text data.
If you might have
or something (ie, not something that is legal to use in numeric
evaluations), then you need something slightly better. Then COMPRESS is
data text_data num_data;
if missing(compress(datavar,,'d')) and not(find(trim(datavar),' ')) then
else output text_data;
should do it; compress(datavar,,'d') should remove all digits (numbers) from
the variable and leave everything else, only failing if there are spaces [as
in my example], as space is equivalent to missing in SAS; the find function
should handle those cases.
On Thu, Jul 7, 2011 at 5:01 PM, Chris Bat <email@example.com> wrote:
> Hi all, happy thursday! I don't think this is to terribly difficult to
> accomplish but I've dug around and can't find anything; it may also be that
> after spending 10 hours in front of my computer today, I'm a little tired.
> I have received over 102,000 rows of lab data, with patient ID, result date
> / time, result, test, and a pile of other stuff. What I've noticed is that
> there are many more alpha-based results than I was expecting (I was told to
> expect 15%, and based on a random sample I'm seeing closer to 30%). What
> I'd like to do is somehow split the comment-type results (which would be
> alpha, at least in part) into a new table, and the numeric results into a
> third (thus leaving my original table untouched). I tried proc sort, but
> because some comments start with a number, didn't work too well. I thought
> of using a length(result), but there are some results of "unk" and "n/a". I
> tried to pull out anything with something in the Comments field, but that
> didn't work be!
> cause there are valid (although anomalous) results with detailed comments.
> So, I am stumped, and would appreciate any thoughts....