52%let inref=%upcase(&inref);
53%let outref=%upcase(&outref);
54%let action=%upcase(&action);
55%local infound outfound;
59 set sashelp.vextfl(where=(fileref=
"&inref" or fileref=
"&outref"));
60 if fileref=
"&inref" then call symputx(
'infound',1,
'l');
61 if fileref=
"&outref" then call symputx(
'outfound',1,
'l');
64%mp_abort(iftrue= (&infound=0)
66 ,msg=%str(INREF &inref NOT FOUND!)
68%mp_abort(iftrue= (&outref=0)
70 ,msg=%str(OUTREF NOT PROVIDED!)
72%mp_abort(iftrue= (&action ne ENCODE and &action ne DECODE)
74 ,msg=%str(Invalid action! Should be ENCODE OR DECODE)
77%
if &outfound=0 %then %
do;
78 filename &outref temp lrecl=2097088;
81%
if &action=ENCODE %then %
do;
83 length b64 $ 76 line $ 57;
85 infile &inref recfm=F lrecl= 1 end=eof;
86 input @1 stream $char1.;
88 substr(line,(_N_-(CEIL(_N_/57)-1)*57),1) = byte(rank(stream));
89 if mod(_N_,57)=0 or EOF then
do;
90 if eof then b64=put(trim(line),$base64X76.);
91 else b64=put(line, $base64X76.);
97%
else %
if &action=DECODE %then %
do;
99 length filein 8 fileout 8;
100 filein = fopen(
"&inref",
'I',4,
'B');
101 fileout = fopen(
"&outref",
'O',3,
'B');
103 do while(fread(filein)=0);
106 rc=fget(filein,
char,1);
107 substr(raw,i,1)=char;
109 rc = fput(fileout,input(raw,$base64X4.));
110 rc = fwrite(fileout);
113 rc = fclose(fileout);