Date: Thu, 5 Nov 2009 10:49:42 -0500
Reply-To: Mike Rhoads <RHOADSM1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mike Rhoads <RHOADSM1@WESTAT.COM>
Subject: Re: Is there a real null value for character variables?
In-Reply-To: <35eb1739-0451-4611-a1f0-8f691ba7e330@f16g2000yqm.googlegroups.com>
Content-Type: text/plain; charset="iso-8859-1"
In terms of this analogy, it's the difference between a character expression and a character variable.
Functions such as LENGTHC operate on character expressions (which of course could be a character variable). Character expressions can have a length of 0 (explaining the results you get), but character variables, being fixed-length in SAS, have to have a minimum storage length of at least 1.
Mike Rhoads
RhoadsM1@Westat.com
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of PT
Sent: Thursday, November 05, 2009 2:57 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Is there a real null value for character variables?
For my charachter variable spaces can be valid data, that's why I need some other way to sign missing value.
I know there are workarounds, I could use a sparate variable to indicate this.
But it is annoying that SAS cannot handle a real null value for character variables.
Here is a quote from the SAS 9.1.3 documentation for LENGTHC function:
"If the value of string is missing and contains blanks, LENGTHC returns the number of blanks in string. If the value of string is missing and contains no blanks, LENGTHC returns a value of 0."
This definition would mean to me that a charachter variable can be missing containing no blanks.
But I can't find a way to set this value.
Interesting that the TRIMN character function can return such a null value. LENGTHC(TRIMN(alma)) produces zero.
If a character function can produce a real null value, a character variable why not?
Tibor Peák
On nov. 4, 19:59, snoopy...@GMAIL.COM (Joe Matise) wrote:
> SAS stores 'missing'/null/whatever in a character variable as a single
> space per length of variable. IE, an 8 length character variable, in
> hex, would be stored as 2020202020202020
> (or, ' ')
> So once you've initialized Alma as a $4. variable, it starts out having '
> ' in it. No assignment needed :)
>
> As I understand it, uninitialized means that a variable never existed
> in the first place, but you told SAS to keep/drop/etc. it. Never
> existed not as in never had a value, but never was allocated space or
> referred to in the PDV in a way that would cause SAS to allocate it
> space. Not relevant to this discussion.
>
> If the question (turned about) is, "How do I get SAS to consider my
> spaces as nonmissing", then I would use a format; assign some non-used
> character (~ or $ or something) and make that the actual space
> character, then display that as a blank space.
>
> You might also explain a bit further why you feel you need to consider
> space to be a valid entry as a character variable, and some examples
> of code where it's useful; perhaps we could offer alternatives.
>
> -Joe
>
>
>
> On Wed, Nov 4, 2009 at 12:47 PM, PT <peak.ti...@gmail.com> wrote:
> > Does anyone knows a way to assign a real null value for a character
> > variable in SAS data step?
>
> > The 'missing' value is not that I need, because spaces are treated
> > missing by SAS, but for me it would mean data.
>
> > Interesting that SAS knows if a variable is unitialized and comments
> > it in the log. But how can I check that from the data step (missing
> > function again is not correct), and how can I reset a variable to
> > uninitalized (set it a real null value)?
>
> > Here is a sample data step:
>
> > data _null_;
> > attrib alma format=$4. ;
> > alma = ' ';
> > if missing(alma) then put "alma is missing"; run;
>
> > It will put "alma is missing" even if I stored four spaces in the
> > variable.
> > If I comment out that value assigment, it will be missing, but also
> > I will get a message in the Log that the variable is uninitialized.
> > So the SAS system knows that has been no value stored in the
> > variable, but how can I get that information in the Data Step?
>
> > Thanks for any help
>
> > Tibor Peak- Idézett szöveg elrejtése -
>
> - Idézett szöveg megjelenítése -
|