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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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