SASCRUNCH TRAINING
  • Home
  • SASĀ® Certification Training
    • SAS Certified Specialist Exam Training Program
    • How to Prepare For SAS Certified Specialist Base Programming Exam
  • Online Courses
    • Practical SAS Training Course for Beginners
    • Proc SQL Course
    • SAS Project Training Course
    • Logistic Regression (Credit Scoring) Modeling using SAS
  • Articles
    • Get Started >
      • 18 Free Resources to Help You Learn SAS
      • SAS Tutorial
      • How to Install SAS Studio
      • How to Learn SAS Fast
    • Data Import >
      • Importing Excel Spreadsheet
      • Importing CSV Files
      • Importing Text Files
    • SAS Functions >
      • CAT, CATT, CATS, CATX Functions
      • If-Then-Else statement
      • TRIM Function
      • STRIP Function
      • YEAR, MONTH, DAY Functions
      • Compress Function
      • Do-Loop
      • SCAN Function
      • LIKE Operator
      • INDEX Function
    • Data Manipulations >
      • The Ultimate Guide to Proc SQL
      • Proc Datasets
      • Dictionary Tables
      • Dealing with Missing Values
      • Proc Compare
      • Proc Transpose
      • RETAIN Statement
      • SAS Formats
      • SAS Arrays
    • Statistical Analysis >
      • Proc Means
      • Proc Freq
      • Proc Tabulate
    • Machine Learning >
      • Predicting Fish Species Using K-nearest Neighbor in SAS
      • Classify Product Reviews on Amazon Using Naive Bayes Model in SAS
    • Informational Interviews >
      • How to get a Clinical Trial/Research job without experience
      • Senior Recruiter at a Fortune 500 Retail Company
      • Manager, Non-profit Health Services Research
      • HR Manager
      • Quantitative Analyst
  • Services
    • The Ultimate Job Search Automation Services
    • Statistical Consulting
    • SAS Project or Assignment Help
    • Data Import Services
    • Data Manipulation and Reporting Services
  • In-class Training
    • SAS Training for Job Seekers
  • Guest Lecture
  • Sample Resume
  • About us
  • Contact Us
Practical SAS Training Course for Beginners


Get Access to:
​
  • 90+ Training ​Modules
  • 150+ ​Practice ​Exercises
  • 5 ​Coding ​Projects
  • 1000+​ Satisfied ​Students
Start your Free training!
x
Picture
Need help studying for the new
SAS Certified Specialist Exam?
Get access to:
  • Two Full Certificate Prep Courses
  • ​300+ Practice Exercises
Picture
Start your free training now
How to Prepare for the SAS Certified Specialist Base Programming Exam
Picture
 

Compress Function

How to Remove Blank Spaces or Selected Characters From Character Values in SAS


The COMPRESS function is often used to remove blank spaces from a character value.

Let's look at some examples.
Picture

The data set above contains a single character value.

Remove Blank Spaces from Character Value

You can use the COMPRESS function to remove all of the blank spaces in a character value.
data string2;
set string;
comp = compress(text);
run;

The COMPRESS function compresses the character value and removes all of the blank spaces from the string.
Picture

Remove Selected Characters from Character Value


You can also specify a character to be removed in the COMPRESS function.

​Example
data string2;
set string;
comp = compress(text, 'a');
run;

The character 'a' is specified in the second parameter of the COMPRESS function. It is removed from the text.
Picture

Remove Multiple Characters from Character Value


Multiple characters can be removed simultaneously in the COMPRESS function.
​
​Example
data string2;
set string;
comp = compress(text, 'abc');
run;

The 3 letters 'a', 'b', and 'c' are specified in the second parameters.

​All 3 letters are removed from the text.
Picture

Please note that the capital letters 'A', 'B' and 'C' remain in the text. You can add a modifier in the third parameter to ignore case of the characters to be removed.

Ignore Case of Characters To Be Removed


Adding the 'i' modifier to the third parameter of the COMPRESS function tells SAS to ignore the case of the characters when removing them from the text.

​Example
data string2;
set string;
comp = compress(text, 'abc', 'i');
run;

In this example, all 6 letters of 'A', 'B', 'C', 'a', 'b', and 'c' are removed from the string.
Picture

Remove All Alphabetic Characters

You can use the 'a' modifier to remove all of the alphabetic characters from the text.
data string2;
set string;
comp = compress(text, '', 'a');
run;

In addition to the blank space specified in the second parameter, the 'a' modifier in the third parameter tells SAS to remove all of the alphabetic characters from the text.
Picture

Remove All Digits

Similar to the 'a' modifier, the 'd' modifier removes all of the digits from the text.
data string2;
set string;
comp = compress(text, '', 'd');
run;
Picture

Are you totally new to SAS?
Picture
Take our Practical SAS Training Course for Beginners and learn how to code your first SAS program!
Start learning now

 

Master SAS in 30 Days

Start your Free training now!
Copyright © 2012-2019 SASCrunch.com All rights reserved.
  • Home
  • SASĀ® Certification Training
    • SAS Certified Specialist Exam Training Program
    • How to Prepare For SAS Certified Specialist Base Programming Exam
  • Online Courses
    • Practical SAS Training Course for Beginners
    • Proc SQL Course
    • SAS Project Training Course
    • Logistic Regression (Credit Scoring) Modeling using SAS
  • Articles
    • Get Started >
      • 18 Free Resources to Help You Learn SAS
      • SAS Tutorial
      • How to Install SAS Studio
      • How to Learn SAS Fast
    • Data Import >
      • Importing Excel Spreadsheet
      • Importing CSV Files
      • Importing Text Files
    • SAS Functions >
      • CAT, CATT, CATS, CATX Functions
      • If-Then-Else statement
      • TRIM Function
      • STRIP Function
      • YEAR, MONTH, DAY Functions
      • Compress Function
      • Do-Loop
      • SCAN Function
      • LIKE Operator
      • INDEX Function
    • Data Manipulations >
      • The Ultimate Guide to Proc SQL
      • Proc Datasets
      • Dictionary Tables
      • Dealing with Missing Values
      • Proc Compare
      • Proc Transpose
      • RETAIN Statement
      • SAS Formats
      • SAS Arrays
    • Statistical Analysis >
      • Proc Means
      • Proc Freq
      • Proc Tabulate
    • Machine Learning >
      • Predicting Fish Species Using K-nearest Neighbor in SAS
      • Classify Product Reviews on Amazon Using Naive Bayes Model in SAS
    • Informational Interviews >
      • How to get a Clinical Trial/Research job without experience
      • Senior Recruiter at a Fortune 500 Retail Company
      • Manager, Non-profit Health Services Research
      • HR Manager
      • Quantitative Analyst
  • Services
    • The Ultimate Job Search Automation Services
    • Statistical Consulting
    • SAS Project or Assignment Help
    • Data Import Services
    • Data Manipulation and Reporting Services
  • In-class Training
    • SAS Training for Job Seekers
  • Guest Lecture
  • Sample Resume
  • About us
  • Contact Us