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;
177 fmthash=%mp_md5(cvars=&cvars, nvars=&nvars);
183data &inlibds/nonote2err;
184 length &delete_col $3 FMTROW 8 start end label $32767;
185 if 0 then set &base_fmts;
187 by type fmtname notsorted;
188 if &delete_col='' then &delete_col='No';
189 fmtname=upcase(fmtname);
191 if missing(type) then do;
192 if substr(fmtname,1,1)='@' then do;
193 if substr(fmtname,2,1)='$' then type='J';
197 if substr(fmtname,1,1)='$' then type='C';
201 if type in ('N','I') then do;
202 %mp_aligndecimal(start,width=16)
203 %mp_aligndecimal(end,width=16)
206 fmthash=%mp_md5(cvars=&cvars, nvars=&nvars);
213create table &outds_add(drop=&delete_col) as
216 left join &base_fmts b
217 on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
218 where b.fmtname is null
219 and upcase(a.&delete_col) ne "YES"
220 order by type, fmtname, fmtrow;
225create table &outds_mod (drop=&delete_col) as
228 inner join &base_fmts b
229 on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
230 where upcase(a.&delete_col) ne "YES"
231 and a.fmthash ne b.fmthash
232 order by type, fmtname, fmtrow;
237create table &outds_del(drop=&delete_col) as
240 inner join &base_fmts b
241 on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
242 where upcase(a.&delete_col)="YES"
243 order by type, fmtname, fmtrow;
254 left join &outds_del b
255 on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
256 where b.fmtrow is null;
259 select * from &outds_del
260 where cats(type,fmtname) not in (select cats(type,fmtname) from &outds_add)
261 and cats(type,fmtname) not in (select cats(type,fmtname) from &del1);
267 ,msg=%str(SYSCC=&syscc prior to load prep)
270%if &loadtarget=YES %then %do;
273 merge &base_fmts(in=base)
277 if not del and not mod;
278 by type fmtname fmtrow;
285 by type fmtname fmtrow;
292 ,msg=%str(SYSCC=&syscc prior to actual load)
294%if &loadtarget=YES %then %do;
295 %if %mf_nobs(&stagedata)=0 and %mf_nobs(&del2)=0 %then %do;
296 %put There are no changes to load in &libcat!;
299 %if &locklibds ne 0 %then %do;
301 %mp_lockanytable(LOCK
302 ,lib=%scan(&libcat,1,.)
303 ,ds=%scan(&libcat,2,.)-FC
304 ,ref=MP_LOADFORMAT commencing format load
309 proc format lib=&libcat cntlin=&stagedata;
312 %if %mf_nobs(&del2)>0 %then %do;
315 select distinct case when type='N' then cats(fmtname,'.FORMAT')
316 when type='C' then cats(fmtname,'.FORMATC')
317 when type='J' then cats(fmtname,'.INFMTC')
318 when type='I' then cats(fmtname,'.INFMT')
319 else cats(fmtname,'.BADENTRY!!!') end
323 proc catalog catalog=&libcat;
327 %if &locklibds ne 0 %then %do;
329 %mp_lockanytable(UNLOCK
330 ,lib=%scan(&libcat,1,.)
331 ,ds=%scan(&libcat,2,.)-FC
332 ,ref=MP_LOADFORMAT completed format load
337 %if &auditlibds ne 0 %then %do;
338 %if &locklibds ne 0 %then %do;
339 %mp_lockanytable(LOCK
340 ,lib=%scan(&auditlibds,1,.)
341 ,ds=%scan(&auditlibds,2,.)
342 ,ref=MP_LOADFORMAT commencing audit table load
347 %mp_storediffs(&libcat-FC
357 proc append base=&auditlibds data=&storediffs;
360 %if &locklibds ne 0 %then %do;
361 %mp_lockanytable(UNLOCK
362 ,lib=%scan(&auditlibds,1,.)
363 ,ds=%scan(&auditlibds,2,.)
364 ,ref=MP_LOADFORMAT commencing audit table load
373 ,msg=%str(SYSCC=&syscc after load)
376%if &mdebug=0 %then %do;
377 proc datasets lib=work;
380 %put &sysmacroname exit vars:;