75%macro mp_applyformats(inds,errds=0
77%local outds liblist i engine lib msg ;
86%
if &errds=0 %then %let outds=%mf_getuniquename(prefix=mp_applyformats);
87%
else %let outds=&errds;
91 where fmt not in (
'',
'.',
'$',
'$CHAR.',
'8.');
94 if libref(lib) ne 0 then
do;
95 msg=catx(
' ',
'libref',lib,
'is not assigned!');
96 %
if &errds=0 %then %
do;
97 putlog
'ERR' +(-1)
"OR: " msg;
102 if exist(cats(lib,
'.',ds)) ne 1 then
do;
103 msg=catx(
' ',
'libds',lib,
'.',ds,
'does not exist!');
104 %
if &errds=0 %then %
do;
105 putlog
'ERR' +(-1)
"OR: " msg;
110 %mp_validatecol(fmt,FORMAT,is_fmt)
112 msg=catx(
' ',
'format',fmt,
'on libds',lib,
'.',ds,
'.',var,
'is not valid!');
113 %
if &errds=0 %then %
do;
114 putlog
'ERR' +(-1)
"OR: " msg;
122 dsid=open(cats(lib,
'.',ds));
124 msg=catx(
' ',
'libds',lib,
'.',ds,
' could not be opened!');
125 %
if &errds=0 %then %
do;
126 putlog
'ERR' +(-1)
"OR: " msg;
131 if varnum(dsid,var)<1 then
do;
132 msg=catx(
' ',
'Variable',lib,
'.',ds,
'.',var,
' was not found!');
133 %
if &errds=0 %then %
do;
134 putlog
'ERR' +(-1)
"OR: " msg;
139 if last.ds then rc=close(dsid);
143select distinct lib into: liblist separated by
' ' from &inds;
145%
if %length(&liblist)>0 %then %
do i=1 %to %sysfunc(countw(&liblist));
146 %let lib=%scan(&liblist,1);
147 %let engine=%mf_getengine(&lib);
148 %
if &engine ne V9 and &engine ne BASE %then %
do;
149 %let msg=&lib has &engine engine - formats cannot be applied;
150 insert into &outds
set lib=
"&lib",ds=
"_all_",var=
"_all", msg=
"&msg" ;
151 %
if &errds=0 %then %put %str(ERR)OR: &msg;
156%
if %mf_nobs(&outds)>0 %then %
return;
161%let fref=%mf_getuniquefileref();
165 where fmt not in (
'',
'.',
'$',
'$CHAR.',
'8.');
167 if first.lib then put
'proc datasets nolist lib=' lib
';';
168 if first.ds then put
' modify ' ds
';';
169 put
' format ' var fmt
';';
170 if last.ds then put
' run;';
171 if last.lib then put
'quit;';
176%
if &errds=0 %then %
do;
181%mend mp_applyformats;