BookmarkSubscribeRSS Feed
milts
Pyrite | Level 9
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
4 REPLIES 4
Vince_SAS
Rhodochrosite | Level 12
Try:
[pre]
%if (%datatyp(%bquote(&nVal)) ne NUMERIC) and (&nVal ne ) %then %do;
[/pre]

Vince DelGobbo
SAS R&D
milts
Pyrite | Level 9
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
Vince_SAS
Rhodochrosite | Level 12
Try using BQUOTE on the other reference to NVAL, too.

Vince DelGobbo
SAS R&D
chang_y_chung_hotmail_com
Obsidian | Level 7
%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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1203 views
  • 0 likes
  • 3 in conversation