How do I use the COMPBL function in SAS? Can you provide some examples? 2

How do I use the COMPBL function in SAS? Can you provide some examples?

The COMPBL function in SAS is used to remove any extra blank spaces from a character string. This function is useful when manipulating data and cleaning up messy data sets. To use the COMPBL function, simply input the character string that you want to remove extra spaces from. The function will then return the same string with all extra spaces removed. For example, if the string “SAS COMPBL function” is inputted, the function will return “SAS COMPBL function” with only one space between each word. This function can be used in various scenarios, such as cleaning up data for analysis or creating more presentable outputs.

Use the COMPBL Function in SAS (With Examples)


You can use the COMPBL function in SAS to compress multiple blanks in a character string into a single blank.

The following example shows how to use the COMPBL function in practice.

Example: How to Use COMPBL Function in SAS

Suppose we have the following dataset in SAS that contains the names of various people:

/*create dataset*/
data original_data;
    input name $char30.;
    datalines;
Andy   Douglas
James Mike      Thomas
Arthur   McNeely   Stevenson
Jake Smith
Arnold Walker
Graham    Johnson
Grant  Beeson
;
run;

/*view dataset*/
proc reportdata=original_data;
    define name / display style=[asis=on];
run;

Note: We used PROC REPORT with the option DISPLAY STYLE=[ASIS=ON] to force SAS to display multiple blanks in the output.

Notice that some of the names have multiple blanks in between the individual words.

We can create a new dataset in which we use the COMPBL function to compress multiple blanks in each name into single blanks:

/*create new dataset*/
data new_data;
    set original_data;
    compbl_name = compbl(name);
run;

/*view new dataset*/
proc reportdata=new_data;
    define name / display style=[asis=on];
run;

COMPBL function in SAS example

Notice that each of the names now only have single blanks.

The COMPBL function compressed all multiple blanks into single blanks.

Note that this is different than the function in SAS, which can be used to remove blanks entirely from strings.

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How do I use the COMPBL function in SAS? Can you provide some examples?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-do-i-use-the-compbl-function-in-sas-can-you-provide-some-examples/

stats writer. "How do I use the COMPBL function in SAS? Can you provide some examples?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-do-i-use-the-compbl-function-in-sas-can-you-provide-some-examples/.

stats writer. "How do I use the COMPBL function in SAS? Can you provide some examples?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-do-i-use-the-compbl-function-in-sas-can-you-provide-some-examples/.

stats writer (2024) 'How do I use the COMPBL function in SAS? Can you provide some examples?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-do-i-use-the-compbl-function-in-sas-can-you-provide-some-examples/.

[1] stats writer, "How do I use the COMPBL function in SAS? Can you provide some examples?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How do I use the COMPBL function in SAS? Can you provide some examples?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top