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

I have a character column like this

 

aaa_xyz

bbb_yxz

ccc_zyx

 

Now I want to break this  column into two columns, one

aaa

bbb

ccc

and the other

xyz

yxz

zyx

 

How can I do that quickly in SAS EG? I know in Excel it can be done quickly by text to column… but SAS EG's split column function does something else… not want I want...

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Not sure how you would do it by clicking on things, but it is trivial to do with a program.

So if you have a variable names MYVAR in a dataset named HAVE you can use this program to create a new dataset called WANT that adds two now columns names COL1 and COL2.

data want;
  set have;
  length col1 col2 $10 ;
  col1 = scan(myvar,1,'_');
  col2 = scan(myvar,2,'_');
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Not sure how you would do it by clicking on things, but it is trivial to do with a program.

So if you have a variable names MYVAR in a dataset named HAVE you can use this program to create a new dataset called WANT that adds two now columns names COL1 and COL2.

data want;
  set have;
  length col1 col2 $10 ;
  col1 = scan(myvar,1,'_');
  col2 = scan(myvar,2,'_');
run;
joeFurbee
Community Manager

and if you want to get rid of the original column, add the drop option into @Tom's code:

data want;
   set have;
   length col1 col2 $10;
   col1 = scan(myvar,1,'_');
   col2 = scan(myvar,2,'_');
   drop myvar;
run;

 


Join us for SAS Community Trivia
SAS Bowl XLIII, The New SAS Developer Portal
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 773 views
  • 1 like
  • 3 in conversation