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 XL, SAS Innovate 2024 Recap
Wednesday, May 15, 2024, at 10 a.m. ET | #SASBowl

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 674 views
  • 1 like
  • 3 in conversation