|
Or, if a boundary-less solution is required, use macro:
%macro typevar (data=, var=);
%local dsid ;
%let dsid = %sysfunc(open (&data));
%if &dsid %then %do;
%let varnum = %sysfunc (varnum (&dsid, &var));
%if &varnum %then %do;
%sysfunc (vartype(&dsid, &varnum));
%end; %else %do;
Invalid variable
%end;
%let dsid = %sysfunc(close(&dsid));
%end; %else %do;
Invalid dataset
%end;
%mend;
%put %typevar(data=scores,var=score_desc)
Returns C, N or one of the "Invalid .." messages.
-----Original Message-----
From: Marianne Whitlock [mailto:WHITLOM1@WESTAT.COM]
Sent: Monday, November 18, 2002 12:19 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Is a variable Numeric?
Regarding your first question "How do I check if a variable is
numeric?",
I assumed you meant in a SAS file. I imagined your having a macro
which
handles many datasets, and many variables, and your program needs to
know
whether a particular variable (&VARNAME) in a particular dataset
(&DSNAME)
is numeric or character. You could get the answer into a macro
variable,
and then make use of the result in a subsequent step:
proc sql noprint;
select upcase(TYPE) into: CHARNUM
from dictionary.columns
where LIBNAME="AAA"
and upcase(MEMNAME)=upcase("&DSNAME")
and upcase(NAME)=upcase("&VARNAME")
;
quit;
%put CHARNUM=&CHARNUM;
-----Original Message-----
From: GADI_B@MALAM.COM [mailto:GADI_B@MALAM.COM]
Sent: Monday, November 18, 2002 3:53 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Is a variable Numeric?
Hi all,
How do I check if a variable is numeric?
How do I check if a text variable has numeric content (only digits,
a period
and a sign)?
TIA
Gadi
|