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.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 876 views
  • 0 likes
  • 3 in conversation