Hello,
I need to create a new variable that contains the answer with the highest frequency across variables (SAS version 9.4). For example:
id var
100 2
100 2
100 2
100 4
100 5
101 3
101 3
101 1
101 2
101 3
102 4
102 4
102 5
102 2
102 1
I want to add a new variable, so that:
id newvar
100 2
101 3
102 4
It seems like there should be a relatively simple answer, but can't seem to figure out. I can transpose to wide if that is better. Any advice will be great, thanks!
@at16 You could mark one of the two solutions that you intend to use as accepted and close the thread.
ods output onewayfreqs=test;
proc freq data=;
tables var;
by id;
run;
proc sort data=test;
by id descending frequency;
run;
proc sort data=test nodupkey;
by id;
run;
?
Thank you!
data have;
input id var;
cards;
100 2
100 2
100 2
100 4
100 5
101 3
101 3
101 1
101 2
101 3
102 4
102 4
102 5
102 2
102 1
;
proc freq data=have order=freq noprint;
by id;
tables var/out=temp(drop=percent);
run;
data want;
set temp;
by id;
if first.id;
run;
Thank you for your help!
@at16 I meant mark the one of the above contributors who gave you the solution. lol
@at16 You could mark one of the two solutions that you intend to use as accepted and close the thread.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.