1.

HeightWeight69112.5708489.57865.397.557.388

Answer»

RETAIN statement causes a variable that is defined during the input statement to be retained across data set iterations, in other words, retain statement retains the variable value at each iteration and keeps on substituting it, the pdv does not get cleared when you use the retain statement, LET’s try to understand the basic example explained below –

Table - mylib.clinical

OBSIDsYOBDATEdiag1daig2daig3daig4daig5
11002-Mar-862-Mar-18D4500D450
21002-Mar-865-Mar-180D4500D45
31002-Mar-868-Mar-180C50
C50D45
41015-Jan-808-Jan-1800D45D450
51015-Jan-802-Feb-18D4500D450
61015-Jan-8027-Feb-180D4500D45
71015-Jan-8024-Mar-18D450D4500
81015-Jan-8018-Apr-18D4500D450

Suppose we have the above clinical table in the form of SAS Dataset in lib – ‘mylib’. CONSIDERING the fact the following code will give the DESIRED results.

Data Clinical_Analysis; Set mylib.clinical; If '01JAN2018'D <= Date <= '31MAR2019'D ; array diag(*) $diag1 - diag5; do i=1 to 5; if diag(i) in ('D45') then f_diag =1; END; run; proc sort data = Clinical_Analysis; by IDs date; run; Data diag_pat (keep = IDs YOB Date f_diag first_date diag age); set Clinical_Analysis; by Ids; format first_date date9.;

retain diag first_date age; /*retaining diag first_date and age at every iteration */

if first. Ids then do; diag=0; first_date =date; age =0; end; age = Year(first_date) - yob; if f_diag =1 then diag=1; if last.Ids; run; Proc freq data = diag_pat; title "All required counts"; tables diag age/missing list; run;

output: 

Dataset of the code – Table: diag_pat

OBS
IDs
YOB
Date
f_diag
first_date
diag
Age
1
100
2-Mar-86
8-Mar-18
1
2-Mar-18
1
32
4
101
5-Jan-80
18-Apr-18
1
8-Jan-18
1
38


Discussion

No Comment Found