-
Notifications
You must be signed in to change notification settings - Fork 2
/
_colddeck.sas
116 lines (86 loc) · 2.79 KB
/
_colddeck.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
%put NOTE: You have called the macro _COLDDECK, 2022-10-12.;
%put NOTE: Copyright (c) 2022 Rodney Sparapani;
%put;
/*
Author: Rodney Sparapani <rsparapa@mcw.edu>
Created: 2022-05-18
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this file; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
%macro _colddeck(var=_numeric_, data=&syslast, out=REQUIRED, seed=REQUIRED,
attrib=, by=, firstobs=, drop=, keep=, obs=, rename=, sortedby=, where=,
log=);
%_require(&out &seed);
%if %length(&log) %then %_printto(log=&log);
%_sort(data=&data, out=&out, attrib=&attrib, by=&by, firstobs=&firstobs,
drop=&drop, keep=&keep, obs=&obs, rename=&rename, sortedby=&sortedby,
where=&where);
%if %length(&log) %then %_printto;
%local i k n rename temp vars;
%let n=%_nobs(data=&out);
%let vars=%_blist(data=&out, var=&var, nofmt=1);
%let k=%_count(&vars);
%do i=1 %to &k;
%local var&i;
%let var&i=%scan(&vars, &i, %str( ));
%let temp=&temp _&&var&i;
%let rename=&rename &&var&i=_&&var&i;
%end;
data &out;
array _var(&k) &vars;
array _temp(&k) &temp;
array _miss(&k) _temporary_;
drop j _seed_ &temp;
_seed_=&seed;
do i=1 to &n;
set &out point=i;
do while(nmiss(of &var1--&&var&k));
do j=1 to &k;
_miss(j)=nmiss(_var(j));
end;
%_ranuni(var=h, seed=_seed_, upper=&n);
h=ceil(h);
set &out(keep=&vars rename=(&rename)) point=h;
do j=1 to &k;
if _miss(j) then _var(j)=_temp(j);
end;
end;
output;
end;
stop;
run;
%mend _colddeck;
%*VALIDATION TEST STREAM;
/* un-comment to re-validate
%let list=white black other hispanic male sbp pulse rr;
libname pwd '.';
proc import datafile='/data/shared/04224/NTDB/NTDB18.csv'
out=pwd.ntdb18;
guessingrows=max;
run;
*/
/*
%let list=white black other hispanic male sbp pulse rr;
libname pwd '.';
%_colddeck(data=pwd.ntdb18, out=ntdb18, var=&list, seed=21);
data ntdb18;
set pwd.ntdb18 ntdb18(in=_imputed_);
imputed=_imputed_;
run;
proc means mean stddev min max nmiss;
class imputed;
var sbp pulse rr;
run;
proc freq;
tables imputed*male imputed*white*black*other / list missing;
run;
*/