How can the FINDC function be used in SAS? 2

How can the FINDC function be used in SAS?

FINDC is a SAS function that is used to search for a specific character or string within a given text or variable. It can be used in SAS programming to locate and extract specific information from large datasets, such as identifying and retrieving specific records or values. FINDC can also be used to manipulate and clean data by replacing or removing certain characters within a string. This function is particularly useful for data analysis and data management tasks, as it provides a quick and efficient way to search and manipulate text data in SAS.

Use the FINDC Function in SAS


You can use the FINDC function in SAS to return the position of the first occurrence of any individual character within a string.

This function uses the following basic syntax:

FINDC(string, charlist)

where:

  • string: The string to analyze
  • charlist: The list of characters to search for within source

The following example shows how to use this function in practice.

Example: Using the FINDC Function in SAS

Suppose we have the following dataset in SAS that contains a column of names:

/*create dataset*/
data original_data;
    input name $25.;
    datalines;
Andy Lincoln Bernard
Barren Michael Smith
Chad Simpson Arnolds
Derrick Smith Henrys
Eric Millerton Smith
Frank Giovanni Goode
;
run;

/*view dataset*/
proc printdata=original_data;

We can use the FINDC function to search for the position of the first occurrence of the characters x, yorz:

/*find position of first occurrence of either x, y or z in name*/
data new_data;
    set original_data;
    first_xyz = findc(name, 'xyz');
run;

/*view results*/
proc printdata=new_data;

The new column called first_xyz displays the position of the first occurrence of the characters x, yorz in the name column.

If none of these three characters are present in the name column, then the FINDC function simply returns a value of 0.

For example, from the output we can see:

The position of the first occurrence of x, y or z in the first row is in position 4. We can see that the character in position 4 in the first row is a y.

And so on.

The Difference BETWEEN FIND and FINDC Functions

The FIND function in SAS returns the position of the first occurrence of a particular substring in another string.

The following example illustrates the difference between the FIND and FINDC functions:

/*create new dataset*/
data new_data;
    set original_data;
    find_smith = find(name, 'Smith');
    findc_smith = findc(name, 'Smith');
run;

/*view new dataset*/
proc printdata=new_data;

The find_smith column displays the position of the first occurrence of the substring ‘Smith’ in the name column.

The findc_smith column displays the position of the first occurrence of the letters s, m, i, torh in the name column.

For example, from the output we can see:

The substring ‘Smith’ never occurs in the first name so find_smith returns a value of 0.

The letter i occurs in the 7th position of the first name so findc_smith returns a value of 7.

And so on.

The following tutorials explain how to use other common functions in SAS:

Cite this article

stats writer (2024). How can the FINDC function be used in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-findc-function-be-used-in-sas/

stats writer. "How can the FINDC function be used in SAS?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-the-findc-function-be-used-in-sas/.

stats writer. "How can the FINDC function be used in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-findc-function-be-used-in-sas/.

stats writer (2024) 'How can the FINDC function be used in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-findc-function-be-used-in-sas/.

[1] stats writer, "How can the FINDC function be used in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can the FINDC function be used in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

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