There are many patid's in my data sets. Each patid contains many rows. comment where the value is missing like in the posted one (attachment).
dataset structure:
2 lbnam's are grouped into one but some lbnames not.
output should be based on patid, visit and lbnam
sample data: and please find attachment for output sholud look like ..
PatID | Visit | lbnam | Group | Value |
ID001 | 1 | A | 1 | 21 |
ID001 | 1 | B | 1 | |
ID001 | 1 | C | 2 | |
ID001 | 1 | D | 2 | |
ID001 | 1 | E | 3 | 11 |
ID001 | 1 | F | 3 | 22 |
ID001 | 2 | A | 1 | |
ID001 | 2 | C | 2 | 22 |
ID001 | 2 | D | 2 | 11 |
ID001 | 2 | E | 3 | 33 |
ID001 | 2 | F | 3 | 11 |
ID001 | 2 | G | 2 | |
ID001 | 2 | H |
I think that the following does what you want:
data want (drop=counter nmiss); do until (last.group); set have; by PatID Visit Group notsorted; if first.Group then do; counter=1; nmiss=0; end; else counter+1; if missing(value) then nmiss+1; end; do until (last.group); set have; by PatID Visit Group notsorted; if nmiss gt 0 and not missing(group)then do; if counter eq nmiss and counter gt 1 then comment='Y'; else comment='N'; end; output; end; run;
Art, CEO, AnalystFinder.com
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.