SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
echoli
Obsidian | Level 7

Hi all,

 

I have an example data below. What I want is:

I have a new column named Toxicity. If HGB > 8.0 and retic > 0.08 occurs at the same time, then Toxicity = "None", otherwise Toxicity = "Yes"

I don't know how to do with multiple if conditions but different event names...any idea?

 

 

data Lab;
    input ID  Event $ Result;
datalines;

1 ANC 3200
1 HGB 7.7
1 Retic 0.3839
1 Platelet 384
2 ANC 1500
2 HGB 9.3
2 Retic 0.1118
2 Platelet 232
3 ANC 2000
3 HGB 10.4
3 Retic 0.2987
3 Platelet 418
;
run;

in my example, the Toxicity with "None" should be ID = 2 and ID = 3. 

 

Thanks,

C

1 ACCEPTED SOLUTION

Accepted Solutions
MINX
Obsidian | Level 7

Proc transpose for HGB and Retic to determinate the status of Toxicity. Then merge back with lab data by id. Sample codes are below

 

proc transpose data=lab out=Toxicity;
by id;
where event in('HGB' 'Retic');
var result;
id event;
run;

data Toxicity;
	length  Toxicity $10;
	set Toxicity;
	if HGB > 8 and Retic > 0.08 then  Toxicity = "YES";
	else  Toxicity = "None";
	keep id Toxicity;
run;

data want;
	merge lab Toxicity;
	by id;
run;

View solution in original post

5 REPLIES 5
ballardw
Super User

Please show what you expect the output to look like.

Since your data set is in terms of Event And Result then it appears that you want to set toxicity for ID based on two different Events.

Are the order of HGB and Retic for Event within ID always the same with Event=HGB always followed by Event=Retic?

echoli
Obsidian | Level 7

my expected output should be:

 

IDEventResultToxicity
1ANC3200None
1HGB7.7None
1Retic0.3839None
1Platelet384None
2ANC1500Yes
2HGB9.3Yes
2Retic0.1118Yes
2Platelet232Yes
3ANC2000Yes
3HGB10.4Yes
3Retic0.2987Yes
3Platelet418Yes

 

Yes, my conditions should be with two different events (HGB and Retic) and the order is not always HGB then Retic, it maybe orderless.

 

Thanks,

C

gamotte
Rhodochrosite | Level 12

Hello,

 

proc sort data=Lab;
   by ID;
run;

data want;
    set Lab;
	by ID;
	retain chk;

	format Toxicity $4.;

	keep ID Toxicity;

	if first.ID then chk=0;

	if (Event="HGB" and result>8) or (Event="Retic" and result>0.08) then chk=chk+1;

	if last.ID then do;
		if chk=2 then Toxicity="None";
		else Toxicity="Yes";

		output;
	end;
run;
MINX
Obsidian | Level 7

Proc transpose for HGB and Retic to determinate the status of Toxicity. Then merge back with lab data by id. Sample codes are below

 

proc transpose data=lab out=Toxicity;
by id;
where event in('HGB' 'Retic');
var result;
id event;
run;

data Toxicity;
	length  Toxicity $10;
	set Toxicity;
	if HGB > 8 and Retic > 0.08 then  Toxicity = "YES";
	else  Toxicity = "None";
	keep id Toxicity;
run;

data want;
	merge lab Toxicity;
	by id;
run;

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 5 replies
  • 53050 views
  • 0 likes
  • 5 in conversation