BookmarkSubscribeRSS Feed
JKUW
Calcite | Level 5

Study ID

Drug1

Drug2

Drug3

00001

1

0

0

00001

0

0

1

 

Hello,

 

I just started using SAS again and I have yet to refresh my memory.

I'm currently investigating 3 drugs - patients are only supposed to be prescribed to only 1 drug.

However, some patients received more than 1 drug (as depicted in the table above) and I want to delete these specific individuals from the data.

Any codes to identify and delete these individuals? Any advice/help would be appreciated.

 

3 REPLIES 3
novinosrin
Tourmaline | Level 20
Hi, There's studyid but where is Patient/individual id? Please post a more comprehensive sample of what you have and want. Thank you
JKUW
Calcite | Level 5

Hi novinosrin,

 

Study_ID in this case would be the patient_id.

 

unison
Lapis Lazuli | Level 10

Maybe this:

data have;
	format studyid z5.;
	input studyid drug1-drug3;
	datalines;
00001 1 0 0
00001 0 0 1
00002 0 1 0
;
run;

data want;
	set have;
	by studyid;

	if first.studyid then
		rx_total=0;
	rx_total+sum(of drug:);

	if last.studyid and rx_total=1 then
		output;
	drop rx_total;
run;

assumes only one drug can be 1 for any given observation.

-unison

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 3 replies
  • 795 views
  • 0 likes
  • 3 in conversation