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

Hi Guys,

I need one minor help.

Below is my input data;

802,803

803,804

60,61

817,818

817,818,819

810,811,812

55,56

55,56,57

 

I want output like below;

803

804

61

818

818,819

811,812

56

56,57

 

I want to remove data comes before first comma.

How can I do this.

1 ACCEPTED SOLUTION

Accepted Solutions
Amir
PROC Star

The following finds the first comma and then uses substr() to get the text after that:

 

data have;
   input text : $char50.;

   datalines;
802,803
803,804
60,61
817,818
817,818,819
810,811,812
55,56
55,56,57
;

data want;
   set have;
   text2 = substr(text,findc(text,',')+1);
run;

 

Kind regards,

Amir.

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Your data is character, right?

PeterClemmensen
Tourmaline | Level 20

Do something like this

 

data have;
input value $ 1-20;
datalines;
802,803
803,804
60,61
817,818
817,818,819
810,811,812
55,56
55,56,57
;

data want;
  set have;
  value = prxchange("s/([^,]+),//", 1, value);
run;

Result:

 

value
803
804
61
818
818,819
811,812
56
56,57
Amir
PROC Star

The following finds the first comma and then uses substr() to get the text after that:

 

data have;
   input text : $char50.;

   datalines;
802,803
803,804
60,61
817,818
817,818,819
810,811,812
55,56
55,56,57
;

data want;
   set have;
   text2 = substr(text,findc(text,',')+1);
run;

 

Kind regards,

Amir.

Soham0707
Obsidian | Level 7

Thank you so much ...

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
  • 5 replies
  • 698 views
  • 0 likes
  • 3 in conversation