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

I have a large data set with a bunch of redundant values in many columns.  each column corresponds to a variable, and repeats the same value for the other remaining variables like below;

COLUMN 1COLUMN 2 ends in _xCOLUMN 3ends in _yCOLUMN 4 ends in _w
x112 3
y112 3
z112 3
w112 3
x251 4
y251 4
z251 4
w251 4
a251 4

x,y,z,w,a, etc. are the variables.
where x1,y1,z1,w1 are part data for customer 1 and x1,y2,z2,w2,a2 are data of customer 2.

column 1 is the value for variable x, and it's value repeats for the rest of the variables for that customer.

 

How can I aggregate these into one column for each variable for the customer like below;

COLUMN 1AGGREGATE COLUMN
x11
y12
z1
w13
x25
y21
z2
w2
a24


I'm not sure how to tell SAS to serach the column name for the variable, and return just that value.

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

You can use FIND() function to search the values of a variable and then create a new variable based on that.

 

if find(column1,'x','i') then new_col=column_x;
else if find(column1,'y','i') then new_col=column_y;
...................so on.
Thanks,
Suryakiran

View solution in original post

1 REPLY 1
SuryaKiran
Meteorite | Level 14

You can use FIND() function to search the values of a variable and then create a new variable based on that.

 

if find(column1,'x','i') then new_col=column_x;
else if find(column1,'y','i') then new_col=column_y;
...................so on.
Thanks,
Suryakiran

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
  • 1 reply
  • 3117 views
  • 0 likes
  • 2 in conversation