To find out the non missing values of any particular variable at any particular position with conditional statement like it should be greater than or less than
SUB VISIT SBP DBP WEIGH
10001 | 1 | 129 | 110 | 59 |
10001 | 2 | 140 | 106 | 57 |
10001 | 3 | 55 | ||
10001 | 4 | 164 | 100 | 54 |
10001 | 5 | 92 | 56 | |
10002 | 1 | 156 | 103 | 82 |
10002 | 2 | 80 | ||
10002 | 3 | 81 | ||
10002 | 4 | 128 | 92 | 79 |
10002 | 5 | 134 | 81 | |
10003 | 1 | 161 | 78 | 90 |
10003 | 2 | 88 | ||
10003 | 3 | 85 | 87 | |
10003 | 4 | 139 | 89 | |
10003 | 5 | 120 | 77 | 91 |
10004 | 1 | 134 | 105 | 87 |
10004 | 2 | 85 | ||
10004 | 3 | 160 | 98 | 86 |
10004 | 4 | 139 | 88 | 89 |
10004 | 5 | 77 | 90 | |
10005 | 1 | 147 | 102 | 98 |
10005 | 2 | 95 | 96 | |
10005 | 3 | 100 | 99 | |
10005 | 4 | 150 | 97 | 100 |
10005 | 5 | 143 | 85 | 98 |
10006 | 1 | 139 | 94 | |
10006 | 2 | 128 | 90 | |
10006 | 3 | 135 | 85 | 93 |
10006 | 4 | 95 | ||
10006 | 5 | 79 | 91 |
1. Get only latest non-missing values from on or before 3 visit into 3 different data sets for DBP, SBP and Weight variables. I am not able to put questions in wright words.
2. Merge all three, SBP, DBP, WEIGHT
I appreciate if you guide me how to write the code. I am expecting this answer, which is marked in red color.
Thanks.
Your "want" data are inconsistent; with sub 10005 you want the first dbp, although there have been measurements at every visit, so by your rule the value from visit 3 should have been chosen.
Hard to understand you . Subject 10003 's weight 87 should not mark as red ?
Suppose I know what you mean.
data have; input SUB VISIT SBP DBP WEIGH ; cards; 10001 1 129 110 59 10001 2 140 106 57 10001 3 . . 55 10001 4 164 100 54 10001 5 . 92 56 10002 1 156 103 82 10002 2 . . 80 10002 3 . . 81 10002 4 128 92 79 10002 5 134 . 81 ; run; data want; set have; by sub; retain s d w found; if first.sub then do;found=0;n=0;end; if not missing(sbp) and not missing(dbp) and not found then do;s=sbp;d=dbp;end; if not missing(weigh) and not found then w=weigh; n+1; if n gt 2 then found=1; if last.sub; keep sub s d w ; run;
Xia Keshan
How is this question different from this
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.