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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1673 views
  • 1 like
  • 4 in conversation