InterviewSolution
| 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
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
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||