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

I have a string of the following numbers which I would like to separate with commas.

 

000100002000300040005

 

Expected:

 

0001,0002,0003,0004,0005

 

I do not at any point know the length of the string.

 

Thanks in advance

1 ACCEPTED SOLUTION
3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Are they always four characters?  If not how do you know where one starts and one stops?

If they are always four then:

data want;
  str="000100002000300040005";
  length new_str $200;
  do i=0 to lengthn(str)/4;
    new_str=catx(",",new_str,substr(str,(i*4)+1,4));
  end;
run;

However that doesn't get your output as 00002 is not four.  You need to have some logical base to split the string.

Ksharp
Super User

Just for fun.

 

data have;
x='00010002000300040005';
length want $ 200;
do i=1 to length(x);
 if mod(i,4)=1 then want=catx(',',want,char(x,i)); 
  else want=cats(want,char(x,i));
end;
run;

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!

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
  • 1050 views
  • 1 like
  • 4 in conversation