Comparing Old Library to New Library
libname raw "P:/Data/2019-11-26" ;
libname newraw "P:/Data/2019-11-27" ;
*Get names of all datasets;
proc contents data=raw._all_ out=raw(keep=memname name label);
run;
proc contents data=newraw._all_ out=newraw(keep=memname name label);
run;
*Compare contents;
proc compare data=raw compare=newraw;
run;
*This will compare the datasets;
%macro compare;
proc sql;
select count(distinct memname)
into: count trimmed
from raw;
select distinct(memname)
into: ds1 - :ds&count
from raw;
quit;
%do i= 1 %to &count;
proc compare data=raw.&&ds&i compare=newraw.&&ds&i;
run;
%end;
%mend compare;
%compare;
Decimal Align Macro
/**********************************************************
*
* Program Name : dec_align.sas
* Level / Study :
* Type : Macro
* Description : Fix aligment issues
*
*
* Author : L McNaught Ltd
* Date Created : 27OCT2017
* Program Status : Draft
*
*
**********************************************************
* Amended :
* Date Amended :
* Amended By :
**********************************************************/
%macro dec_align(dsin=, test=, aval=, dsout=);
proc sql noprint;
select type
into: type
from sashelp.vcolumn
where libname= "WORK" and memname= %upcase("&dsin") and name= %upcase("&aval");
quit;
data check;
set &dsin. %if &type = num %then %do;(rename=(&aval=test))%end;;
n= _n_;
%if &type = num %then %do;
&aval= strip(put(test, best.));
%end;
run;
data check1;
set check;
len= length(&aval);
dec= find(&aval, ".");
if dec ne 0 then postlen= length(substr(&aval, dec, len)) - 1;
else postlen= .;
if dec ne 0 then prelen= length(substr(&aval, 1, dec)) - 1;
else prelen= length(substr(&aval, 1, len));
run;
proc sql noprint;
select max(prelen)
into: max
from check1;
select count(*)
into: count trimmed
from check1;
quit;
data check1a;
set check1;
max= &max;
if postlen ne . then do;
maxlen= max + postlen + 1;
decput= strip(put(maxlen, best.)) || "." || strip(put(postlen, best.));
end;
run;
data &dsout;
set check1a;
length &aval._dec $200;
do i = 1 to &count;
if n= i then do;
if postlen= . then &aval._dec= put(input(&aval, best.), &max..);
else if postlen ne . then do;
&aval._dec= putn(input(&aval,best.), decput);
end;
end;
end;
run;
%mend dec_align;
Covert pdf to txt file (where var names withing [])
data crf;
*change max length if needed;
length col1 $2000;
infile 'P:\XX\XX\XX\XX\XX\XX\CRF_AS_TXT_FILE.txt' dlm='09'x dsd;
input col1 $ ;
*bring in line number for sort order;
line = _n_;
run;
*sort in descending order in order to get page number at bottom of page;
proc sort data=crf out=crf1;
by decending line;
run;
data crf2;
retain pageno ;
set crf1;
*create page var & find raw var names;
if index(col1, "Page") > 0 then pageno = col1;
if index(col1,"[") >0 and index(col1,"]") > 0 then flag = "Y";
run;
proc sort data=crf2 out=crf3;
by line;
run;
data crf4;
retain module;
set crf3;
*add module;
if index(col1, "XX_TITLE:") > 0 then module = col1;
findmax=length(compress(col1,']','k'));
run;
*find max number of raw var;
proc sql noprint;
select max(findmax)
into: maxn trimmed
from crf4;
quit;
data varname(drop=col1 flag findmax i pos1 pos2 diff pageno check);
set crf4;
*only bring in raw var names;
where flag= "Y" ;
array varname {*} $40 variable1-variable&maxn. ;
do i = 1 to &maxn. by 1;
check = index(col1, "]");
if check ne 0 then do;
*get varname outside of [];
pos1 = find(col1, '[') ;
pos2 = find(col1, ']');
diff = pos2-(pos1+1);
varname{i}= upcase(substr(col1, pos1+1, diff));
col1= substr(col1, pos2+1);
end;
end;
*get pageno as numeric;
page = input(scan(pageno, 2), best.);
run;
proc transpose data= varname out=varname2(rename=(col1=variable));
by line page module;
var variable: ;
run;
proc sort data= varname2 out=crf_page(keep=page module variable) nodupkey;
by page variable;
where variable ne "";
run;
/*
**************CHECK ALL RAW VARS*************;
proc sql;
create table check1 as
select name as variable length=2000, memname
from sashelp.vcolumn
where libname= "RAW";
quit;
proc sort data=check1 out=check2 nodupkey;
by variable;
run;
proc sort data=crf_page out=crf_temp;
by variable;
run;
data check3;
merge check2 crf_temp(in=a);
by variable;
if a then origin= "CRF";
last= substr(reverse(trim(variable)), 1, 1);
run;
data check4;
set check3;
where origin ne "CRF" and last ne "L";
run;*/