BookmarkSubscribeRSS Feed
SrikanthY
Calcite | Level 5

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
1 REPLY 1
art297
Opal | Level 21

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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1006 views
  • 0 likes
  • 2 in conversation