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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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