65%macro mp_loadformat(libcat,libds
69 ,delete_col=_____DELETE__THIS__RECORD_____
76%local err msg prefix dslist i var fmtlist ibufsize;
77%let dslist=base_fmts
template inlibds ds1 stagedata storediffs del1 del2;
78%
if &outds_add=0 %then %let dslist=&dslist outds_add;
79%
if &outds_del=0 %then %let dslist=&dslist outds_del;
80%
if &outds_mod=0 %then %let dslist=&dslist outds_mod;
81%let prefix=%substr(%mf_getuniquename(),1,21);
82%
do i=1 %to %sysfunc(countw(&dslist));
83 %let var=%scan(&dslist,&i);
85 %let &var=%upcase(&prefix._&var);
89%let libcat=%scan(&libcat,1,-);
93 iftrue=(%mf_existds(&libds)=0)
95 ,msg=%str(&libds could not be found)
98 iftrue=(%mf_existvar(&libds,FMTROW)=0)
100 ,msg=%str(FMTROW not found in &libds)
105 if _n_=1 then putlog
"&sysmacroname entry vars:";
107 where scope=
"&sysmacroname";
109 if &mdebug=0 then put name
'=' value;
110 if name=:
'LOAD' and value not in (
'YES',
'NO') then do;
111 call symputx('msg',"invalid value for "!!name!!":"!!value);
112 call symputx('err',1);
115 else if name='LIBCAT' then do;
116 if exist(value,'CATALOG') le 0 then do;
117 call symputx('msg',"Unable to open catalog: "!!value);
118 call symputx('err',1);
122 else if (name=:'OUTDS' or name in ('DELETE_COL','LOCKLIBDS','AUDITLIBDS'))
123 and missing(value) then do;
124 call symputx('msg',"missing value in var: "!!name);
125 call symputx('err',1);
131 if missing(fmtrow) then do;
132 call symputx('msg',"missing fmtrow in format: "!!FMTNAME);
133 call symputx('err',1);
146select count(distinct catx('|',type,fmtname,fmtrow)) into: cnt from &libds;
148 iftrue=(&cnt ne %mf_nobs(&libds))
150 ,msg=%str(Non-unique primary key on &libds)
159 when type='N' then upcase(fmtname)
160 when type='C' then cats('$',upcase(fmtname))
161 when type='I' then cats('@',upcase(fmtname))
162 when type='J' then cats('@$',upcase(fmtname))
163 else "&sysmacroname:UNHANDLED"
165 into: fmtlist separated by ' '
168%mp_cntlout(libcat=&libcat,fmtlist=&fmtlist,cntlout=&base_fmts)
172%let cvars=TYPE FMTNAME START END LABEL PREFIX FILL SEXCL EEXCL HLO DECSEP
173 DIG3SEP DATATYPE LANGUAGE;
174%let nvars=FMTROW MIN MAX DEFAULT LENGTH FUZZ MULT NOEDIT;
175data &base_fmts/note2err;
188data &inlibds/nonote2err;
189 length &delete_col $3 FMTROW 8 start end label $32767 fmthash $32;
190 if 0 then set &base_fmts;
192 by type fmtname notsorted;
193 if &delete_col='' then &delete_col='No';
194 fmtname=upcase(fmtname);
196 if missing(type) then do;
197 if substr(fmtname,1,1)='@' then do;
198 if substr(fmtname,2,1)='$' then type='J';
202 if substr(fmtname,1,1)='$' then type='C';
206 if type in ('N','I') then do;
207 %mp_aligndecimal(start,width=16)
208 %mp_aligndecimal(end,width=16)
222create table &outds_add(drop=&delete_col) as
225 left join &base_fmts b
226 on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
227 where b.fmtname is null
228 and upcase(a.&delete_col) ne "YES"
229 order by type, fmtname, fmtrow;
234create table &outds_mod (drop=&delete_col) as
237 inner join &base_fmts b
238 on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
239 where upcase(a.&delete_col) ne "YES"
240 and a.fmthash ne b.fmthash
241 order by type, fmtname, fmtrow;
246create table &outds_del(drop=&delete_col) as
249 inner join &base_fmts b
250 on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
251 where upcase(a.&delete_col)="YES"
252 order by type, fmtname, fmtrow;
263 left join &outds_del b
264 on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
265 where b.fmtrow is null;
268 select * from &outds_del
269 where cats(type,fmtname) not in (select cats(type,fmtname) from &outds_add)
270 and cats(type,fmtname) not in (select cats(type,fmtname) from &del1);
276 ,msg=%str(SYSCC=&syscc prior to load prep)
279%if &loadtarget=YES %then %do;
282 merge &base_fmts(in=base)
286 if not del and not mod;
287 by type fmtname fmtrow;
294 by type fmtname fmtrow;
301 ,msg=%str(SYSCC=&syscc prior to actual load)
303%if &loadtarget=YES %then %do;
304 %if %mf_nobs(&stagedata)=0 and %mf_nobs(&del2)=0 %then %do;
305 %put There are no changes to load in &libcat!;
308 %if &locklibds ne 0 %then %do;
310 %mp_lockanytable(LOCK
311 ,lib=%scan(&libcat,1,.)
312 ,ds=%scan(&libcat,2,.)-FC
313 ,ref=MP_LOADFORMAT commencing format load
318 proc format lib=&libcat cntlin=&stagedata;
321 %if %mf_nobs(&del2)>0 %then %do;
324 select distinct case when type='N' then cats(fmtname,'.FORMAT')
325 when type='C' then cats(fmtname,'.FORMATC')
326 when type='J' then cats(fmtname,'.INFMTC')
327 when type='I' then cats(fmtname,'.INFMT')
328 else cats(fmtname,'.BADENTRY!!!') end
332 proc catalog catalog=&libcat;
336 %if &locklibds ne 0 %then %do;
338 %mp_lockanytable(UNLOCK
339 ,lib=%scan(&libcat,1,.)
340 ,ds=%scan(&libcat,2,.)-FC
341 ,ref=MP_LOADFORMAT completed format load
346 %if &auditlibds ne 0 %then %do;
347 %if &locklibds ne 0 %then %do;
348 %mp_lockanytable(LOCK
349 ,lib=%scan(&auditlibds,1,.)
350 ,ds=%scan(&auditlibds,2,.)
351 ,ref=MP_LOADFORMAT commencing audit table load
356 %mp_storediffs(&libcat-FC
366 proc append base=&auditlibds data=&storediffs;
369 %if &locklibds ne 0 %then %do;
370 %mp_lockanytable(UNLOCK
371 ,lib=%scan(&auditlibds,1,.)
372 ,ds=%scan(&auditlibds,2,.)
373 ,ref=MP_LOADFORMAT commencing audit table load
382 ,msg=%str(SYSCC=&syscc after load)
385%if &mdebug=0 %then %do;
386 proc datasets lib=work;
389 %put &sysmacroname exit vars:;