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 (July 2009, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 23 Jul 2009 13:11:02 -0400
Reply-To:     Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject:      Re: Does First Key Variable Have to be Numeric?

in addition some remarks: there are normally 2 sources for a variable definition without length. One is a SET statement with the variable contained in the dataset. For that there is no need use any LENGTH. The second is, you are defining a new variable. For that it is ALWAYS a VERY GOOD IDEA (!!!) to use LENGTH to define type and length! A variable can also be defined implicite via assignement. For numerics that is ok, but for character you should avoid that. The reason is, that the length is defined by the first assigned value. If the first is shorter than the rest, you have a problem. That problem might occure not always, but could change depending on data constellations! That are nice problems: sometimes they occure, sometimes not... In your situation you have another problem: not only the length cannot be detected, but also the type and the default is numeric. In that situation it is absolutely necessary to tell SAS what it is, in others, if you define new variables, it is a good idea to avoid problems. Gerhard

On Thu, 23 Jul 2009 11:42:39 -0400, Chang Chung <chang_y_chung@HOTMAIL.COM> wrote:

>On Thu, 23 Jul 2009 11:25:12 -0400, John McPeek <jmcpeek@EGISTAR.COM> wrote: >... >> The first >>variable in the key, D_St, is character. It's the postal abbreviation >>for states. What's with the data type mismatch error message in the log >>below? >> >>1304 DATA HitsFile (Keep = D_St D_City O_Code_1); Set TestFile; RUN; >... >>1308 DATA _NULL_; >>1309 If _N_ = 1 then do; >>1310 Declare Hash PickList (Dataset: 'HitsFile'); >>1311 RC = PickList.DefineKey(ALL: 'YES'); >>1312 PickList.DefineDone(); >>1313 Call Missing(D_St, D_City, O_Code_1, Count); >>1314 End; >>1315 RC = PickList.Output(Dataset: 'ListPick'); >>1316 RUN; >> >>ERROR: Type mismatch for key variable D_St at line 1312 column 9. > >Hi, John, >The variable D_St appears first time (in the data step) when the missing >call routine is called in line 1313. So the compiler assumes it is a numeric >by default. But in your dataset HistFile, it is a character. That's the >reason why you get the errer. You can force a character type before the call >and you are fine. Hope this helps a bit. >Cheers, >Chang > > >data _null_; > if _n_ = 1 then do; > dcl hash lookup(dataset: 'sashelp.class(keep=name age)'); > lookup.defineKey(all: 'y'); > lookup.defineDone(); /* this is line 32 */ > call missing(name, age); > end; >run; >/* on log >ERROR: Type mismatch for key variable name at line 32 column 5. >ERROR: Hash data set load failed at line 32 column 5. >ERROR: DATA STEP Component Object failure. Aborted during the EXECUTION >phase. >*/ > >/* this one does not error */ >data _null_; > if _n_ = 1 then do; > dcl hash lookup(dataset: 'sashelp.class(keep=name age)'); > lookup.defineKey(all: 'y'); > lookup.defineDone(); /* this is line 32 */ > length name $8; /* force character type */ > call missing(name, age); > end; >run;


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