Posts

Showing posts with the label compress
Extracting the First Three Alphabetic Characters in SAS: A Comparative Guide Extracting the First Three Alphabetic Characters in SAS: A Comparative Guide When working with "Agreement" numbers that contain both alphabetic and numeric characters, there are several approaches you can use in SAS to extract the first three alphabetic characters. Below, I’ll discuss three common methods: substr with findc , substr with compress , and substr with left . Each method has its own advantages and disadvantages, depending on the structure of your data and your specific needs. Approach 1: substr with findc char_part = substr(Agreement, 1, findc(Agreement, '0123456789')-1); Explanation: This approach finds the position of the first numeric character in the Agreement string using findc , and then extracts all characters before that position using substr . It works well if the alphabetic part of the "Agreement" is always at the beginnin...

COMPRESS: SAS Function strips characters from the string

In SAS 9.1.3 , an extra argument ( MODIFIER ) is added to the SAS character string function COMPRESS and these modifiers modifies the action of the COMPRESS function; Syntax : COMPRESS ( <, chars><, modifiers>) ; Following characters can be used as modifiers. a – Compress or Delete all upper and lower case characters from String. ak - Compress or Delete alphabetic characters(1,2,3 etc) from String. kd- Compress or Delete characters(aplabets) from String.( Keeps only digits). d – Compress or Delete numerical values from String. i – Compress or Delete specified characters both upper and lower case from String. k – keeps the specified characters in the string instead of removing them. l – Compress or Delete lowercase characters from String. p – Compress or Delete Punctuation characters from String. s – Compress or delete spaces from String. This is default. u – Compress or Delete uppercase characters from String. See the Example below: data ...