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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1161 views
  • 0 likes
  • 3 in conversation