Your SAS programs, embedded in web apps and elsewhere

datatyp on storedprocess

Reply
Super Contributor
Posts: 318

datatyp on storedprocess

hi experts,

i have this piece of code on my stored process, validating input from a form. Alphanumeric should only be the valid values for the variable, else i'll be displaying an error on the output.

%if %datatyp(&nVal) ne NUMERIC and &nVal ne %str() %then %do;
%let invThreshold = 1;
%let isClean = 1;
%end;

problem I'm having problems validating special characters. when the value of the macro variable nVal is either of the ff:

!@#$%&_=[]\<>`;:?

the stored process will correctly display the result. indicating an error message. however when the value of the macro variable is either of the ff:

*+-()/~^|

the stored process will result into an error. I noticed that these characters are used for equations(addition,subtraction,etc.)

What's the proper way to mask nVal so whenever the the input values is either of the following i'll be able to handle them properly?

Thanks in advance,
Milton
SAS Employee
Posts: 285

Re: datatyp on storedprocess

Try:
[pre]
%if (%datatyp(%bquote(&nVal)) ne NUMERIC) and (&nVal ne ) %then %do;
[/pre]

Vince DelGobbo
SAS R&D
Super Contributor
Posts: 318

Re: datatyp on storedprocess

Hi Vince,

Still no go when it comes to characters used for equations. You can test it with this piece of code, just replace the value on symput.

data _null_;
call symput('nVal','-');
run;

%macro test;
%if (%datatyp(%bquote(&nVal)) ne NUMERIC ) and (&nVal ne ) %then %do;
%put if clause;
%end;
%else %do;
%put else clause;
%end;
%mend;
%test

Thanks,
Milton
SAS Employee
Posts: 285

Re: datatyp on storedprocess

Try using BQUOTE on the other reference to NVAL, too.

Vince DelGobbo
SAS R&D
Regular Contributor
Posts: 241

Re: datatyp on storedprocess

%bquote() does not quote & and %, while the implicit %eval() (between '%if' and '%then') considers & as a logical AND operator. That is, the %bquote() is an inadequate choice of macro quoting function in this case. Assign "SAS R&D" to nVal and run the macro %test and see what happens! :-) I would rather suggest %superq().

See if reading this paper helps a bit: http://changchung.com/download/022-2009.pdf
Ask a Question
Discussion stats
  • 4 replies
  • 247 views
  • 0 likes
  • 3 in conversation