LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2002, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 17 May 2002 08:49:43 -0400
Reply-To:   Quentin McMullen <QuentinMcMullen@WESTAT.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Quentin McMullen <QuentinMcMullen@WESTAT.COM>
Subject:   determining variable type
Content-Type:   text/plain; charset="iso-8859-1"

Hi All,

Recently when working on a previous SAS-L question I stumbled across the following surprise in the way SAS determines whether a variable is character or numeric.

If I code the below simple DOW-loop everything is fine.

data a; input Var1 $1; cards; x A x a ; run;

data b; do until (var1='A'); set a; end; run;

But if I change the do until to test (upcase(var1)='A') I get the following error:

70 data b; 71 do until (upcase(var1)='A'); 72 set a; ERROR: Variable var1 has been defined as both character and numeric. 73 end; 74 run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 71:20 NOTE: The SAS System stopped processing this step because of errors.

I understand that SAS determines the type and length of a variable during compile time at the first reference to the variable. In my first example SAS makes var1 character with length 1 (type and length being determined by the comparison to a character string of length 1). Apparently when the variable is an argument to a function, SAS defines it as numeric, even if it is a character function and being compared to a character string.

Of course the fix (and better practice in general), is to add a length statement at the top to define both the type and length of the var1, but I thought this was interesting.

Kind Regards, --Quentin


Back to: Top of message | Previous page | Main SAS-L page