74%macro mp_applyformats(inds,errds=0
76%local outds liblist i engine lib msg ;
85%
if &errds=0 %then %let outds=%mf_getuniquename(prefix=mp_applyformats);
86%
else %let outds=&errds;
90 where fmt not in (
'',
'.',
'$',
'$CHAR.',
'8.');
93 if libref(lib) ne 0 then
do;
94 msg=catx(
' ',
'libref',lib,
'is not assigned!');
95 %
if &errds=0 %then %
do;
96 putlog
'ERR' +(-1)
"OR: " msg;
101 if exist(cats(lib,
'.',ds)) ne 1 then
do;
102 msg=catx(
' ',
'libds',lib,
'.',ds,
'does not exist!');
103 %
if &errds=0 %then %
do;
104 putlog
'ERR' +(-1)
"OR: " msg;
109 %mp_validatecol(fmt,FORMAT,is_fmt)
111 msg=catx(
' ',
'format',fmt,
'on libds',lib,
'.',ds,
'.',var,
'is not valid!');
112 %
if &errds=0 %then %
do;
113 putlog
'ERR' +(-1)
"OR: " msg;
121 dsid=open(cats(lib,
'.',ds));
123 msg=catx(
' ',
'libds',lib,
'.',ds,
' could not be opened!');
124 %
if &errds=0 %then %
do;
125 putlog
'ERR' +(-1)
"OR: " msg;
130 if varnum(dsid,var)<1 then
do;
131 msg=catx(
' ',
'Variable',lib,
'.',ds,
'.',var,
' was not found!');
132 %
if &errds=0 %then %
do;
133 putlog
'ERR' +(-1)
"OR: " msg;
138 if last.ds then rc=close(dsid);
142select distinct lib into: liblist separated by
' ' from &inds;
144%
if %length(&liblist)>0 %then %
do i=1 %to %sysfunc(countw(&liblist));
145 %let lib=%scan(&liblist,1);
146 %let engine=%mf_getengine(&lib);
147 %
if &engine ne V9 and &engine ne BASE %then %
do;
148 %let msg=&lib has &engine engine - formats cannot be applied;
149 insert into &outds
set lib=
"&lib",ds=
"_all_",var=
"_all", msg=
"&msg" ;
150 %
if &errds=0 %then %put %str(ERR)OR: &msg;
155%
if %mf_nobs(&outds)>0 %then %
return;
160%let fref=%mf_getuniquefileref();
164 where fmt not in (
'',
'.',
'$',
'$CHAR.',
'8.');
166 if first.lib then put
'proc datasets nolist lib=' lib
';';
167 if first.ds then put
' modify ' ds
';';
168 put
' format ' var fmt
';';
169 if last.ds then put
' run;';
170 if last.lib then put
'quit;';
175%
if &errds=0 %then %
do;
180%mend mp_applyformats;