data have1;
infile datalines dsd dlm=",";
input subj $ treatment $ painlvl bodypart $;
datalines;
001, A, 1, leg
001, A, 2, leg
002, B, 1, head
003, A, 1, arm
004, B, 1, eye
005, B, 2, mouth
;
run; * choose distinct subjects with highest severity (if more than one instance);
Hello,
information:
* 6 obs
* n=5
* 2 treatment groups (A, B)
Goal: 001 has two reported painful observations in the same area (leg), and the goal is to
output the row where he has the highest pain level, so that my resultant data set will include 5 rows.
Could I receive some help? I tried PROC SQL and using the max() paired w/ the group by clause. It worked but I received an error.
Thanks
data have1; infile datalines dsd dlm=","; input subj $ treatment $ painlvl bodypart $; datalines; 001, A, 1, leg 001, A, 2, leg 002, B, 1, head 003, A, 1, arm 004, B, 1, eye 005, B, 2, mouth ; run; proc sql; create table want as select * from have1 group by subj having painlvl=max(painlvl); quit;
Help us help you. Please show the log including the code and the error message it produced.
Use the "</>" icon to make a text box for that content.
data have1; infile datalines dsd dlm=","; input subj $ treatment $ painlvl bodypart $; datalines; 001, A, 1, leg 001, A, 2, leg 002, B, 1, head 003, A, 1, arm 004, B, 1, eye 005, B, 2, mouth ; run; proc sql; create table want as select * from have1 group by subj having painlvl=max(painlvl); quit;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.