05-19-2014 07:46 AM
I'm trying to pull out the most popular value from a text string and create a new variable that tells me what it is.
'AAAABBBCCD' would give me a new variable with the value of 'A' in this instance.
Can anyone help please?
Thanks in advance.
05-19-2014 08:03 AM
I do not know how many rows of data you are working with; the length of the source variable; nor whether you want the new variable on the same row as the original variable. Are the values in the variable limited to the 26 letters in the alphabet?
05-19-2014 08:10 AM
Please clarify the requirements. There are many string functions, as can be found in the docs: http://support.sas.com/publishing/pubcat/chaps/59343.pdf
However its dependant on your specific scenario. A simple calculation on the A or B or C etc. is relatively straight-forward, however its probably unlikely you want that.
05-19-2014 08:42 AM
The following gives "A":
length want $1;
if tally gt max then
05-19-2014 09:14 AM
05-19-2014 12:04 PM
05-19-2014 09:20 AM
data temp; set sashelp.class(keep=name); do i=1 to length(name); char=upcase(char(name,i)); output; end; drop i; run; proc freq data=temp order=freq noprint; by name; tables char /out=temp1(drop=percent) nopercent ; run; data want; set temp1; by name; if first.name; run;