DATA testnbrs;
INFILE 'phonenum.dat' TRUNCOVER;
INPUT numbs $ 1-10 rcode $ 14-16;
RUN;
PROC PRINT DATA = testnbrs NOOBS;
WHERE numbs = "&mymacro";
TITLE "Testing ALL Phone Numbers";
RUN;
%macro mymacro(numbs,rcode);
if verify(trim(&numbs),"0123456789") > 0 then
do;
&numbs =" ";
&rcode="1";
end;
else if length(trim(&numbs)) ^=10 then
do;
&numbs =" ";
&rcode="1";
end;
else if length(substr(&numbs,1,10)) =10 then
do;
if verify(trim(&numbs),"0123456789") = 0 then
do;
&rcode="0";
end;
if substr(&numbs,1,1) in ("0","1") then
do;
&numbs =" ";
&rcode="1";
end;
else if substr(&numbs,4,1) in ("0","1") then
do;
&numbs =" ";
&rcode="1";
end;
else if substr(&numbs,2,1)="9" then
do;
&numbs =" ";
&rcode="1";
end;
isame = 1;
do i = 5 to 10;
if substr(&numbs,4,1) not = substr(&numbs,i,1) then
isame = 0;
end;
if isame = 1 then
do;
&numbs =" ";
&rcode="1";
end;
end;
%mend mymacro;
Do more with
%macro numbersTest(NN=numberField, RC=returnCode);
...
if substr(&NN, 7, 2) = "62" then &RC = "1";
....
%mend numbersTest;
and call up the macro using the actual variable names you are using in this instance%numbersTest(NN=nums, RC=rcode)
----------01234444444
21237666666
06666666666
44444444444
00000000000
/* first define the macro */
%macro numbersTest(numbs,rcode);
if verify(trim(&numbs),"0123456789") > 0 then
do;
&numbs =" ";
&rcode="1";
end;
else if length(trim(&numbs)) ^=10 then
do;
&numbs =" ";
&rcode="1";
end;
else if length(substr(&numbs,1,10)) =10 then
do;
if verify(trim(&numbs),"0123456789") = 0 then
do;
&rcode="0";
end;
if substr(&numbs,1,1) in ("0","1") then
do;
&numbs =" ";
&rcode="1";
end;
else if substr(&numbs,4,1) in ("0","1") then
do;
&numbs =" ";
&rcode="1";
end;
else if substr(&numbs,2,1)="9" then
do;
&numbs =" ";
&rcode="1";
end;
isame = 1;
do i = 5 to 10;
if substr(&numbs,4,1) not = substr(&numbs,i,1) then
isame = 0;
end;
if isame = 1 then
do;
&numbs =" ";
&rcode="1";
end;
end;
%mend numbersTest;
/* Now run the testing code */
DATA testnbrs;
INFILE 'phonenum.dat' TRUNCOVER;
INPUT numbs $ 1-10;
/* now check the validity of the phone numbers */
/* variable rcode is set to reflect the validity of numbs */
%numbersTest(numbs, rcode)
RUN;
/* summary print */
PROC PRINT DATA = testnbrs NOOBS;
WHERE (rcode = "0");
TITLE "Testing ALL Phone Numbers, numbers with rcode of zero";
RUN;
PROC PRINT DATA = testnbrs NOOBS;
WHERE (rcode = "1");
TITLE "Testing ALL Phone Numbers, numbers with rcode of one";
RUN;
/* specify FOLDER where you want to store all the macros */
/* ******* you fill in the dots ******* */
filename dateauto " ..... ";
/* make sure facility is turned on */
options mautosource;
/* access your date macros as well as SAS supplied macros */
sasautos=(dateauto sasautos);
However you dont want to have to include that every time, so on your sas installation search for sas files autoexec.sas and autoexec_usermods.sas.* specify FOLDER where you want to store all the macros */
/* ******* you fill in the dots ******* */
filename dateauto " ..... ";
/* make sure facility is turned on */
options mautosource;
/* access your date macros as well as SAS supplied macros */
options sasautos=(dateauto sasautos);
Premium Content
You need an Expert Office subscription to comment.Start Free Trial