Need to to out the subjects that have not MHTYPE = "Medical History"
Source Data:
Source Data | ||
Subject | InstanceName | MHTYPE |
1036190 | Screening | SURGICAL HISTORY |
1036192 | Screening | VACCINE HISTORY |
1036192 | Screening | MEDICAL HISTORY |
1036192 | Screening | SURGICAL HISTORY |
1036193 | Screening | VACCINE HISTORY |
1036193 | Screening | MEDICAL HISTORY |
1036193 | Screening | SURGICAL HISTORY |
1036196 | Screening | VACCINE HISTORY |
1036196 | Screening | MEDICAL HISTORY |
1036196 | Screening | SURGICAL HISTORY |
1036197 | Screening | SURGICAL HISTORY |
1036197 | Screening | VACCINE HISTORY |
Expected output:
Expected output | ||
1036190 | Screening | SURGICAL HISTORY |
1036197 | Screening | SURGICAL HISTORY |
1036197 | Screening | VACCINE HISTORY |
data have;
infile datalines delimiter = ",";
input Subject :$8. InstanceName :$10. MHTYPE :$25.;
datalines;
1036190,Screening,SURGICAL HISTORY
1036192,Screening,VACCINE HISTORY
1036192,Screening,MEDICAL HISTORY
1036192,Screening,SURGICAL HISTORY
1036193,Screening,VACCINE HISTORY
1036193,Screening,MEDICAL HISTORY
1036193,Screening,SURGICAL HISTORY
1036196,Screening,VACCINE HISTORY
1036196,Screening,MEDICAL HISTORY
1036196,Screening,SURGICAL HISTORY
1036197,Screening,SURGICAL HISTORY
1036197,Screening,VACCINE HISTORY
;
run;
proc sql;
create table want as
select
*
from
have
where
subject not in (
select
subject
from
have
where
mhtype = "MEDICAL HISTORY"
);
quit;
Subject InstanceName MHTYPE 1036190 Screening SURGICAL HISTORY 1036197 Screening SURGICAL HISTORY 1036197 Screening VACCINE HISTORY
data have;
infile datalines delimiter = ",";
input Subject :$8. InstanceName :$10. MHTYPE :$25.;
datalines;
1036190,Screening,SURGICAL HISTORY
1036192,Screening,VACCINE HISTORY
1036192,Screening,MEDICAL HISTORY
1036192,Screening,SURGICAL HISTORY
1036193,Screening,VACCINE HISTORY
1036193,Screening,MEDICAL HISTORY
1036193,Screening,SURGICAL HISTORY
1036196,Screening,VACCINE HISTORY
1036196,Screening,MEDICAL HISTORY
1036196,Screening,SURGICAL HISTORY
1036197,Screening,SURGICAL HISTORY
1036197,Screening,VACCINE HISTORY
;
run;
proc sql;
create table want as
select
*
from
have
where
subject not in (
select
subject
from
have
where
mhtype = "MEDICAL HISTORY"
);
quit;
Subject InstanceName MHTYPE 1036190 Screening SURGICAL HISTORY 1036197 Screening SURGICAL HISTORY 1036197 Screening VACCINE HISTORY
Thanks a lot, it works fine, Program is simple but effective. You support is really appreciated.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.