BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a dataset that has a variable with a prefix code the a description.

I want to trim the variable by the number of characters the prefix code has but the prefix code can be 4, 5, 6, 7 or 8 characters long.

Is there a way of trimming the data using a procedure?


Thanks
2 REPLIES 2
Patrick
Opal | Level 21
You will have to explain a bit better what you have and what you want. May be you give us also some examples.
deleted_user
Not applicable
The method of trimming a prefix is determined by how the prefix is defined.


The simplest way is for the prefix code and the remaining data to be separated by a unique character, say ':'. Then you can use the "scan" function as in below

trimmed = scan (prefixed, 2, ':');

OR

trimmed = scan (prefixed, -1, ':' );

A more complicated method would be that the prefix is required to be lower case and the first character of the real data is capitalized. Then you would have to use a do loop (do while or do until), the substr function and either the ANYLOWER or ANYUPPER function to find the beginning of the real, non-prefixed, data.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1048 views
  • 0 likes
  • 2 in conversation