Significant Digits

With ADAM implementation we can be sure that BDS structure is same for each sponsor. And that is a blessing I must tell you. We can be sure about the structure of data variables and values within it. We are sure that paramcd contains name of parameter not exceeding 8 characters and aval will contain numeric value of result. Using both these I have created a macro that creates and rounds of each parameter of summary statistics based on input. The user needs to input name of dataset, summary stats needed (n mean median stddev min max) and significant digits associated with respective summary stats in that exact order. The proc means dataset should be named “New” if you want to use this macro as is. This can be changed if the user wants it to be changed. I will also show the proc means code so that the variables generated by you remains same when you use this macro along with proc means so that little or no modification needs to be done in macro

proc means data=adlbc noprint;
class trtpn visit paramcd;
where upcase(visit) ne “UNSCHEDULED”;
var aval;
output out=new(where =(type in (3,7))) n= mean= median= std= min= max= / autoname;
run;

%macro sigdig(ds=,sumpam=,sigdig=);
data &ds.dec &ds.nodec;
set &ds;
if find(put(aval,best.),”.”) then output &ds.dec;
else output &ds.nodec;
run;

proc sql noprint;
select distinct paramcd
into: decmvr
separated by ‘” “‘
from &ds.dec;
quit;

data &ds.nodec;
set &ds.nodec;
where paramcd not in (“&decmvr”);
run;

proc sql ;
create table parmdec as
select paramcd, max(length(strip(put(aval,best.)))) as tot,
max(length(scan(strip(put(aval,best.)),2,”.”)) ) as afterdec

from &ds.dec
group by paramcd;
create table parmnodec as
select paramcd, max(length(strip(put(aval,best.)))) as tot,
0 as afterdec
from &ds.nodec
group by paramcd;

quit;

data parm;
set parmdec parmnodec;
%do j=1 %to %sysfunc(countw(&sigdig));
tot%sysfunc(strip(%scan(&sumpam,&j)))=tot+(%scan(&sigdig,&j))+1;
tot%sysfunc(strip(%scan(&sumpam,&j)))d=afterdec+(%scan(&sigdig,&j));
ft%sysfunc(strip(%scan(&sumpam,&j)))=strip(put(tot%sysfunc(strip(%scan(&sumpam,&j))),best.))||”.”||strip(put(tot%sysfunc(strip(%scan(&sumpam,&j)))d,best.));
call symputx(strip(paramcd)||”%sysfunc(strip(%scan(&sumpam,&j)))”,ft%sysfunc(strip(%scan(&sumpam,&j))));
%put check here strip(paramcd)||”%sysfunc(strip(%scan(&sumpam,&j)))”,ft%sysfunc(strip(%scan(&sumpam,&j)));
putlog ft%sysfunc(strip(%scan(&sumpam,&j))) =;
%end;
run;

proc sql;
create table new2 as
select a.*, b.tot,b.afterdec
from new as a,parm as b
where a.paramcd=b.paramcd;
quit;

proc sql noprint;
select distinct paramcd
into: params
separated by ” “
from &ds.;
quit;
data new3;
%do a=1 %to %sysfunc(countw(&sumpam)); length avalr%sysfunc(strip(%scan(&sumpam,&a))) $200; %end;

set new2;
%do i=1 %to %sysfunc(countw(&params));

if paramcd= “%scan(&params,&i)” then do;
*putlog “%scan(&params,&i)” “=” “%superq(%sysfunc(strip(%scan(&params,&i)))mn)”;
%do l=1 %to %sysfunc(countw(&sumpam));
avalr%sysfunc(strip(%scan(&sumpam,&l)))=put(aval_%sysfunc(strip(%scan(&sumpam,&l))),%superq(%sysfunc(strip(%scan(&params,&i)))%sysfunc(strip(%scan(&sumpam,&l)))));
%end;

end;

%end;
run;

%mend;
%sigdig(ds=adlbc,sumpam=mean stddev median min max,sigdig=1 2 1 0 0);

Leave a comment

Design a site like this with WordPress.com
Get started