BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Derdavos
Obsidian | Level 7

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. 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

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;
Derdavos
Obsidian | Level 7

Thank you! Works very well!! 🙂

PeterClemmensen
Tourmaline | Level 20

Anytime, glad to help 🙂

Astounding
PROC Star

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1254 views
  • 2 likes
  • 4 in conversation