Hey guys
I have to make same but multiple values into one value. Like I have 100, 111, 122, 133, 100, 111, 100, 113, 112 so after I reduce it it should look like: 100, 111, 122, 133, 113. Or for an easier example: there is a lot of 'F' (stands for Female): F, F, F, F, F, F, F and it should look like: just an F.
Thank you. 🙂
Use PROC SORT with the NODUPKEY option like this
data have;
input Gender $;
datalines;
F
F
F
M
M
F
F
M
M
;
proc sort data = have nodupkey out = want;
by Gender;
run;
Please post your example data (in a data step) so we can get a picture of what you want to do.
Use PROC SORT with the NODUPKEY option like this
data have;
input Gender $;
datalines;
F
F
F
M
M
F
F
M
M
;
proc sort data = have nodupkey out = want;
by Gender;
run;
Thank you! Works very well!! 🙂
Anytime, glad to help 🙂
Here's some code that could go in a DATA step:
data new;
set have;
newvar = scan(oldvar, 1, ',');
if length(oldvar) > length(newvar) then do i=2 to countw(oldvar, ',');
next_word = scan(oldvar, i, ',');
if indexw(newvar, strip(nextword))=0 then oldvar = catx(oldvar, ',' , next_word);
end;
run;
It's untested code, so you might need to fiddle with the INDEXW function, but it probably works as is.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.