BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tsureshinvites
Obsidian | Level 7

Need to to out the subjects that have not MHTYPE = "Medical History"

Source Data:

Source Data
SubjectInstanceNameMHTYPE
1036190ScreeningSURGICAL HISTORY
1036192ScreeningVACCINE HISTORY
1036192ScreeningMEDICAL HISTORY
1036192ScreeningSURGICAL HISTORY
1036193ScreeningVACCINE HISTORY
1036193ScreeningMEDICAL HISTORY
1036193ScreeningSURGICAL HISTORY
1036196ScreeningVACCINE HISTORY
1036196ScreeningMEDICAL HISTORY
1036196ScreeningSURGICAL HISTORY
1036197ScreeningSURGICAL HISTORY
1036197ScreeningVACCINE HISTORY

 

Expected output:

Expected output
1036190ScreeningSURGICAL HISTORY
1036197ScreeningSURGICAL HISTORY
1036197ScreeningVACCINE HISTORY
1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ
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 

View solution in original post

2 REPLIES 2
maguiremq
SAS Super FREQ
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 
tsureshinvites
Obsidian | Level 7

Thanks a lot, it works fine, Program is simple but effective. You support is really appreciated.

SAS Innovate 2025: Register Now

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!

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
  • 2 replies
  • 582 views
  • 2 likes
  • 2 in conversation