DATA Step, Macro, Functions and more

Output missing values based on groups

Reply
Occasional Contributor
Posts: 17

Output missing values based on groups

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

 

PatIDVisitlbnamGroupValue
ID0011A121
ID0011B1 
ID0011C2 
ID0011D2 
ID0011E311
ID0011F322
ID0012A1 
ID0012C222
ID0012D211
ID0012E333
ID0012F311
ID0012G 2
ID0012H  

OutputFile.PNG
PROC Star
Posts: 7,363

Re: Output missing values based on groups

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

 

Ask a Question
Discussion stats
  • 1 reply
  • 94 views
  • 0 likes
  • 2 in conversation