Help using Base SAS procedures

Trim data by x characters

Reply
N/A
Posts: 0

Trim data by x characters

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
Respected Advisor
Posts: 3,892

Re: Trim data by x characters

You will have to explain a bit better what you have and what you want. May be you give us also some examples.
N/A
Posts: 0

Re: Trim data by x characters

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.
Ask a Question
Discussion stats
  • 2 replies
  • 107 views
  • 0 likes
  • 2 in conversation