BookmarkSubscribeRSS Feed
Nasya
Obsidian | Level 7

Hi,

 

Please find the code below.

Basing on one of the following conditions are TRUE/FALSE=, the output EARLYD is generated as YES or NO.

There are multiple records for one ID. However, I am having trouble generating the F_EarlyD(column). I have attached the excel with the expected output for reference.

 

Any help is appreciated.

data d4;
	attrib EarlyD length=$4;
        by ID;
	
	if  (upcase (AUNIT) = 'U/L'  AND (AT > 2000)) or 
 	    (upcase (AUNIT) = 'μkat/L'  AND (AT > 33.3)) or
 		(upcase (AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) =  'MG/DL' AND (ASUNIT > = 10)) or
		(upcase(AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) = 'μMOL/L' AND (ASUNIT > = 171.0367)) or 
		(upcase(AST) eq 'INR LEVEL' AND (ASUNIT >= 1.6)) or
		(upcase(PRIMYN) = 'Yes')
	then EarlyD="Yes";
		else EarlyD="No";
run;

Output_Expected:

IDEarlyD?F_EarlyD
01-001YesYes
01-001No 
01-001No 
01-001No 
01-001No 
01-001No 
01-001No 
01-002NoNo
01-002No 
01-003YesYes
01-004YesYes
01-004Yes 
01-004Yes 
01-005NoNo
01-005No 
01-005No 
   

Thank you,

 

Regards,

Nasya

5 REPLIES 5
UdayGuntupalli
Quartz | Level 8

@Nasya,
        Can you give this a shot and let me know if this works ? 

 

data d4;
	attrib EarlyD length=$4;
    by ID;
	
	if  (upcase (AUNIT) = 'U/L'  AND (AT > 2000)) Then  EarlyD="Yes";
 	else if  (upcase (AUNIT) = 'μkat/L'  AND (AT > 33.3)) Then  EarlyD="Yes";
 	else if  (upcase (AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) =  'MG/DL' AND (ASUNIT > = 10)) Then EarlyD = "Yes";
 	else if  (upcase(AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) = 'μMOL/L' AND (ASUNIT > = 171.0367)) Then EarlyD = "Yes";
	else if  (upcase(AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) = 'μMOL/L' AND (ASUNIT > = 171.0367)) Then EarlyD = "Yes";
	else if  (upcase(AST) eq 'INR LEVEL' AND (ASUNIT >= 1.6)) Then EarlyD = "Yes";
	else if  (upcase(PRIMYN) = 'Yes') then EarlyD="Yes";
	else EarlyD="No";
run;

  Just to test it, you may even try running it on one of the SASHelp Datasets like in the example shown below: 

 

data want; 
	set sashelp.class; 
	if age > 13 and sex = 'F' and weight > 55 then cond1 = "yes";
	else if age < 13 and sex = 'M' and weight > 57 then cond1 = "yes"; 
	else cond1 = "no"; 
run;

 

Nasya
Obsidian | Level 7

Hi UdayGuntupalli,

 

I tried the code that you sent me, but it is not giving me the expected output. All the multiple values are being generated in the output as earlier. Is there any other way to fix it?

Thank you,

 

Regards,

Nasya

 

UdayGuntupalli
Quartz | Level 8

@Nasya
         Can you share a sample data set or some code that generates some sample data that provides an example of the data you are working with ? It will be easier to work with the data to trouble shoot the issue or test it in sample data as I showed above. 

Astounding
PROC Star

Here are a couple of places to start.

 

I'm not sure what the upper case of μ would be, you might need to test that.

 

But I'm 100% sure that when you apply UPCASE to AUNIT, it would never contain lower-case letters like "kat".

 

Also, you are using ASUNIT incorrectly in a couple of places.  One of these must be wrong:

 

upcase(ASUNIT) =  'MG/DL' AND (ASUNIT > = 10)

 

Is ASUNIT character (and comparable to MG/DL) or is it numeric (and comparable to 10) ?

 

That's at least a good place to start.  If you notice further problems, it would be a good idea to post the log next time.

Nasya
Obsidian | Level 7

Hi,

Thanks for your response, I will check on the UPCASE conditions.

 

Regards,

Nasya

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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