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 (August 1997, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 17 Aug 1997 14:36:24 -0700
Reply-To:     PDORFMA@ucs.att.com
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Paul Dorfman <PDORFMA@UCS.ATT.COM>
Organization: AT&T Universal Card Services
Subject:      Detecting CHAR/NUM in Data Step
Content-Type: text/plain; charset=us-ascii

Bruce Johnson, in particular, wrote:

>Is there a way to determine if a variable is character or numeric >within a datastep? For the purposes of this situation the use of proc >contents output is prohibited.

Bruce:

Anthony Ayiomamitis is right: VARTYPE function has been added to the list of DATA step functions in Base SAS. Personally, I prefer to keep a macro like

%MACRO VARTYPE(DSNAME,VNAME); %STR(VARTYPE(OPEN("&DSNAME","I"), VARNUM (OPEN("&DSNAME","I"),"&VNAME"))); %MEND VARTYPE;

in an autocall library and to use it as a function-like statement in a data step whenever needed. For instance, in the dataset SASLIB.VRU the variable CALLDATE is numeric whilst the DUP_STMT is character. Accordingly, the execution of the above yields:

134 DATA _NULL_; 135 CD_TYPE = %VTYPE(SASLIB.VRU,CALLDATE); 136 DS_TYPE = %VTYPE(SASLIB.VRU,DUP_STMT); 137 PUT CD_TYPE= DS_TYPE=; 138 RUN;

CD_TYPE=N DS_TYPE=C NOTE: The DATA statement used 0.05 CPU seconds and 5564K.

Hope it's been helpful...

Paul M. Dorfman AT&T UCS Decision Support Systems Jax, Fl


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