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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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