BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Hello_there
Lapis Lazuli | Level 10
data have1;
length soc_term pt_term $10;
infile datalines dsd dlm=",";
	input subj $ soc_term $ pt_term $ aesevn;
datalines;
001, soc_term1, pt_term1, 1
001, soc_term1, pt_term2, 1
001, soc_term1, pt_term2, 2
001, soc_term1, pt_term3, 1
002, soc_term1, pt_term1, 1
002, soc_term2, pt_term1, 2
002, soc_term2, pt_term3, 3
002, soc_term3, pt_term1, 1
003, soc_term1, pt_term1, 1
003, soc_term2, pt_term1, 1
003, soc_term2, pt_term1, 2
003, soc_term3, pt_term1, 1
;
run;

Hi, i am making an AE table, and a rule i'm supposed to follow is that if a subject has multiple AE events (soc_term by pt_term), i'm supposed to output the record with the maximum severity level. What is the most efficient way to do this? 

 

Note, subjects 001 and 003 and have multiple records of soc_termX*pt_termX, and i'm only trying to output record with the highest severity. 

Note: this table below was produced to show the frequency of soc_terms by pt_terms per subject and this is not the desired result. 

Hello_there_0-1663609534013.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

No biggie, just wanted to clarify. Is this what you're after?

 

data have1;
length soc_term pt_term $10;
infile datalines dsd dlm=",";
	input subj $ soc_term $ pt_term $ aesevn;
datalines;
001, soc_term1, pt_term1, 1
001, soc_term1, pt_term2, 1
001, soc_term1, pt_term2, 2
001, soc_term1, pt_term3, 1
002, soc_term1, pt_term1, 1
002, soc_term2, pt_term1, 2
002, soc_term2, pt_term3, 3
002, soc_term3, pt_term1, 1
003, soc_term1, pt_term1, 1
003, soc_term2, pt_term1, 1
003, soc_term2, pt_term1, 2
003, soc_term3, pt_term1, 1
;

proc sql;
   create table want as
   select * from have1
   group by subj, soc_term, pt_term
   having max(aesevn) = aesevn
   ;
quit;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

What is the Proc FREQ output suppose to do here? It is not the desired result, right?

 

Can you post your desired result? Makes it easier to provide a usable code answer.

Hello_there
Lapis Lazuli | Level 10
Hi PeterClemmensen,
It was put there to show that there were two subjects who had multiple records of soc_term by pt_term. My apologies if it's redundant.
PeterClemmensen
Tourmaline | Level 20

No biggie, just wanted to clarify. Is this what you're after?

 

data have1;
length soc_term pt_term $10;
infile datalines dsd dlm=",";
	input subj $ soc_term $ pt_term $ aesevn;
datalines;
001, soc_term1, pt_term1, 1
001, soc_term1, pt_term2, 1
001, soc_term1, pt_term2, 2
001, soc_term1, pt_term3, 1
002, soc_term1, pt_term1, 1
002, soc_term2, pt_term1, 2
002, soc_term2, pt_term3, 3
002, soc_term3, pt_term1, 1
003, soc_term1, pt_term1, 1
003, soc_term2, pt_term1, 1
003, soc_term2, pt_term1, 2
003, soc_term3, pt_term1, 1
;

proc sql;
   create table want as
   select * from have1
   group by subj, soc_term, pt_term
   having max(aesevn) = aesevn
   ;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3386 views
  • 1 like
  • 2 in conversation