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

Hi,

 

Could anyone help me with this issue please? The column is currently is like this:

30012324431440~~PABC

 

I want to extract the 30012324431440 (number part) and PABC(character part) into two different column. And the separation part is ~~.

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tommy1
Quartz | Level 8

https://communities.sas.com/t5/SAS-Procedures/Splitting-a-delimited-column-into-multiple-columns/td-...

Hope this helps

 

data split;
   set test;
   length var1-var2 $15.;
   array var(2) $;
   do i = 1 to dim(var);
      var[i]=scan(row,i,'~~');
   end;
run;

 

View solution in original post

3 REPLIES 3
Tommy1
Quartz | Level 8

https://communities.sas.com/t5/SAS-Procedures/Splitting-a-delimited-column-into-multiple-columns/td-...

Hope this helps

 

data split;
   set test;
   length var1-var2 $15.;
   array var(2) $;
   do i = 1 to dim(var);
      var[i]=scan(row,i,'~~');
   end;
run;

 

ballardw
Super User

One way:

data example;
   str="30012324431440~~PABC";
   numpart = scan(str,1,'~');
   Charpart = scan(str,2,'~');
run;

The Scan function will treat multiple adjacent delimiters, such as the ~, as a single "word" value.

If you want to have an actual numeric value for the numeral part you could add

 

numeric = input(numpart,15.);

but if you have more than 15 digits you will likely run into numeric precision storage issues.

 

profaddae
Calcite | Level 5

data work.one;
     numchar='30012324431440~~PABC';
   format num best15.;
  num=input(substr(numchar,1,14),14.);
   char=substr(numchar,17,4);
run;

 

if you don't format num as best15, it will appear using scientific notation.

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!

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
  • 3 replies
  • 1034 views
  • 1 like
  • 4 in conversation