74%macro mp_storediffs(libds
80 ,outds=work.mp_storediffs
86%
if &mdebug=1 %then %
do;
87 %put &sysmacroname entry vars:;
93%local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist vlist;
94%let ds1=%upcase(work.%mf_getuniquename(prefix=mpsd_ds1));
95%let ds2=%upcase(work.%mf_getuniquename(prefix=mpsd_ds2));
96%let ds3=%upcase(work.%mf_getuniquename(prefix=mpsd_ds3));
97%let ds4=%upcase(work.%mf_getuniquename(prefix=mpsd_ds4));
98%let hashkey=%upcase(%mf_getuniquename(prefix=mpsd_hashkey));
99%let inds_auto=%upcase(%mf_getuniquename(prefix=mpsd_inds_auto));
100%let inds_keep=%upcase(%mf_getuniquename(prefix=mpsd_inds_keep));
103%
if &delds ne 0 %then %
do;
104 %let delds=%upcase(&delds);
105 %
if %scan(&delds,-1,.)=&delds %then %let delds=WORK.&delds;
106 %let dslist=&dslist &delds;
108%
if &appds ne 0 %then %
do;
109 %let appds=%upcase(&appds);
110 %
if %scan(&appds,-1,.)=&appds %then %let appds=WORK.&appds;
111 %let dslist=&dslist &appds;
113%
if &modds ne 0 %then %
do;
114 %let modds=%upcase(&modds);
115 %
if %scan(&modds,-1,.)=&modds %then %let modds=WORK.&modds;
116 %let dslist=&dslist &modds;
119%let origds=%upcase(&origds);
120%
if %scan(&origds,-1,.)=&origds %then %let origds=WORK.&origds;
122%let key=%upcase(&key);
126 set &dslist indsname=&inds_auto;
127 &hashkey=put(md5(catx(
'|',%mf_getquotedstr(&key,quote=N))),$hex32.);
128 &inds_keep=upcase(&inds_auto);
130 by &inds_keep &hashkey;
134proc transpose data=&ds1
135 out=&ds2(rename=(&hashkey=key_hash _name_=tgtvar_nm col1=newval_num));
136 by &inds_keep &hashkey;
139proc transpose data=&ds1
141 rename=(&hashkey=key_hash _name_=tgtvar_nm col1=newval_char)
142 where=(tgtvar_nm not in (
"&hashkey",
"&inds_keep"))
144 by &inds_keep &hashkey;
148%
if %index(&libds,-)>0 and %scan(&libds,2,-)=FC %then %
do;
150 %let vlist=
"TYPE",
"FMTNAME",
"FMTROW",
"START",
"END",
"LABEL",
"MIN",
"MAX"
151 ,
"DEFAULT",
"LENGTH",
"FUZZ",
"PREFIX",
"MULT",
"FILL",
"NOEDIT",
"SEXCL"
152 ,
"EEXCL",
"HLO",
"DECSEP",
"DIG3SEP",
"DATATYPE",
"LANGUAGE";
154%
else %let vlist=%mf_getvarlist(&libds,dlm=%str(,),quote=DOUBLE);
157 length &inds_keep $41 tgtvar_nm $32 _label_ $256;
158 if _n_=1 then call missing(_label_);
160 set &ds2 &ds3 indsname=&inds_auto;
162 tgtvar_nm=upcase(tgtvar_nm);
163 if tgtvar_nm in (%upcase(&vlist));
165 if upcase(&inds_auto)=
"&ds2" then tgtvar_type=
'N';
166 else if upcase(&inds_auto)=
"&ds3" then tgtvar_type=
'C';
168 putlog
'ERR' +(-1)
"OR: unidentified vartype input!" &inds_auto;
169 call symputx(
'syscc',98);
172 if &inds_keep=
"&appds" then move_type=
'A';
173 else if &inds_keep=
"&delds" then move_type=
'D';
174 else if &inds_keep=
"&modds" then move_type=
'M';
175 else if &inds_keep=
"&origds" then move_type=
'O';
177 putlog
'ERR' +(-1)
"OR: unidentified movetype input!" &inds_keep;
178 call symputx(
'syscc',99);
180 tgtvar_nm=upcase(tgtvar_nm);
181 if tgtvar_nm in (%mf_getquotedstr(&key)) then is_pk=1;
186%
if "&loadref"=
"0" %then %let loadref=%sysfunc(uuidgen());
187%
if &processed_dttm=0 %then %let processed_dttm=%sysfunc(datetime(),8.6);
188%let libds=%upcase(&libds);
192create table &outds as
193 select
"&loadref" as load_ref length=36
194 ,&processed_dttm as processed_dttm format=E8601DT26.6
195 ,
"%scan(&libds,1,.)" as libref length=8
196 ,
"%scan(&libds,2,.)" as dsn length=32
197 ,b.key_hash length=32
198 ,b.move_type length=1
199 ,b.tgtvar_nm length=32
201 ,
case when b.move_type ne
'M' then -1
202 when a.newval_num=b.newval_num and a.newval_char=b.newval_char then 0
205 ,b.tgtvar_type length=1
206 ,
case when b.move_type=
'D' then b.newval_num
208 end as oldval_num format=best32.
209 ,
case when b.move_type=
'D' then .
211 end as newval_num format=best32.
212 ,
case when b.move_type=
'D' then b.newval_char
214 end as oldval_char length=32765
215 ,
case when b.move_type=
'D' then
''
217 end as newval_char length=32765
218 from &ds4(where=(move_type=
'O')) as a
219 right join &ds4(where=(move_type ne 'O')) as b
220 on a.tgtvar_nm=b.tgtvar_nm
221 and a.key_hash=b.key_hash
222 order by move_type, key_hash,is_pk desc, tgtvar_nm;
224%if &mdebug=0 %then %do;
226 drop table &ds1, &ds2, &ds3, &ds4;