SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
raveena
Obsidian | Level 7

Hi

I have the below data,

cl_No lineno Servive_code
1       01      120
2       01      D373
2       02      373
2       03      D440
3       01      270
3       02      D20
3       03      D4567
3       04      D567
3       05      F679

The service_code should include a 3 digit service_code and a 4 digit service_code.
The four digit servie_code should begin with the letter "D" and is the last of the
cl_no.

The output should be like this:

cl_No lineno Servive_code
1       01      120
2       02      373
2       03      D440
3       01      270
3       02      D20
3       04      D567

Thanks in advance

1 REPLY 1
ballardw
Super User

Are you looking to keep records:

when the service code is exactly 3 characters they are all digits or any exactly 3 character code?

or

when the service code is exactly 4 characters the first first character is "D"?

I'm not sure what you mean by "and is the last of the cl_no" since your have multiple cl_No values in your output example.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 547 views
  • 0 likes
  • 2 in conversation