Remove leading, trailing, all space SAS- strip(), trim() & compress()

Remove Leading, Trailing, all space in SAS using strip(), trim() and compress() function in SAS. STRIP function in SAS removes all leading and trailing blanks. TRIM function in SAS removes all trailing blanks. COMPRESS function in SAS removes all blanks

  • STRIP function in SAS – removes all leading and trailing blanks
  • TRIM function in SAS – removes all trailing blanks
  • COMPRESS function in SAS – removes all blanks

So we will be using EMP_DET Table in our example
Remove leading, trailing, all space SAS- strip(), trim() & compress() 1

 

 

STRIP function – removes all leading and trailing blanks

STRIP Function in SAS Removes all the leading and Trailing spaces. STRIP() Function takes column name as argument and removes the leading and trailing spaces

/* STRIP function - removes all leading and trailing blanks */ 
 
data EMP_DET1; 
set EMP_DET; 
state_new = STRIP(state_name_code); 
run;

So the resultant table with the leading and trailing spaces removed will beRemove leading, trailing, all space SAS- strip(), trim() & compress() 2

 

TRIM function – removes all trailing blanks

TRIM Function in SAS Removes all the Trailing spaces. TRIM() Function in SAS takes column name as argument and removes the trailing space.

/* TRIM function - removes all trailing blanks */ 

data EMP_DET1; 
set EMP_DET; 
state_new = TRIM(state_name_code); 
run;

So the resultant table with trailing spaces removed will be
Remove leading, trailing, all space SAS- strip(), trim() & compress() 3

 

 

COMPRESS function – removes all the spaces or blanks

COMPRESS Function in SAS Removes all the spaces. COMPRESS() Function takes column name as argument and removes all the spaces

/* COMPRESS function - remove all Blanks */ 
 
data EMP_DET1; 
set EMP_DET; 
state_new = COMPRESS(state_name_code); 
run; 

So the resultant table with all the spaces removed will be
Remove leading, trailing, all space SAS- strip(), trim() & compress() 4