Date: Fri, 9 Dec 2011 02:14:56 -0500
Reply-To: Tom Abernathy <tom.abernathy@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Tom Abernathy <tom.abernathy@GMAIL.COM>
Subject: Re: a macro checking invalid variable name
You first two data lines will result in the same value in the variable
VARNAME. If you want to preserve the leading spaces use the $CHAR informat.
On Thu, 8 Dec 2011 23:58:49 -0500, bbser 2009 <bbser2009@GMAIL.COM> wrote:
>Greetings!
>
>The code below is suppose to check if a given literal can be used as a
>variable name.
>I would like to check the four literals one at a time in the data step.
>Only the first two are suppose to be valid.
>But after running the code, I only got one comment in the log about the
last
>long literal (39 characters long), which said the literal is valid,
>apparently contrary to the name criterion.
>What am I missing here? In addition, do you think I am using %bquote
>correctly?
>Please help. Thank you very much in advance!
>
>Regards, Max
>(Maaxx)
>
>%macro checkvarname(value);
>%let valid=%sysfunc(nvalid(&value,v7));
>%if valid=0 %then
> %do;
> %let position=%sysfunc(notname(&value));
> %put ***The first invalid character of %upcase(&value) is in position:;
> %put &position;
> %end;
>%else
> %put ***%upcase(&value) is a valid variable name.;
> %put;
> %put;
>%mend checkvarname;
>
>data _null_;
>length varname $ 39;
>input varname $ 1-39;
>*the purpose of using %bquote is to preserve blanks at the beginning of
>literals;
>call symput('value',%bquote(trim(varname)));
>%checkvarname(&value)
>cards;
>valid_name
> valid_name
>invalid name
>book_sales_results_for_past_five_years!
>;
|