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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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