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.
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;
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.
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;
Glad you found your answer 🙂
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.
Ready to level-up your skills? Choose your own adventure.