BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aaaaa34
Calcite | Level 5

Hi,

 

What does this function?

 

find(variable1, "&variable2")>0 or

I saw it in some code online.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  Let's remove the macro variable out of the code. The &variable2 is just supplying a search value. In the VARIABLE1, the FIND function is searching for whatever is stored in &variable2.

 

  Consider this example I want to FIND names with "Ja" in them and also want to find names with a lowercase "e" in the name. Notice that FIND returns a number which corresponds to the position of the 2nd argument (what I want to look for).:

what_find_do.png

I made 2 separate variables so you could see that when "Ja" did NOT exist, the value for FVAL1 was 0. When "e" does exist, then FVAL2 shows you the position that "e" occupies in the name. There are 19 rows in SASHELP.CLASS, so I only output the 10 rows I was interested in based on using FIND  on the NAME variable.

 

Cynthia

 

View solution in original post

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

Hi:

  Let's remove the macro variable out of the code. The &variable2 is just supplying a search value. In the VARIABLE1, the FIND function is searching for whatever is stored in &variable2.

 

  Consider this example I want to FIND names with "Ja" in them and also want to find names with a lowercase "e" in the name. Notice that FIND returns a number which corresponds to the position of the 2nd argument (what I want to look for).:

what_find_do.png

I made 2 separate variables so you could see that when "Ja" did NOT exist, the value for FVAL1 was 0. When "e" does exist, then FVAL2 shows you the position that "e" occupies in the name. There are 19 rows in SASHELP.CLASS, so I only output the 10 rows I was interested in based on using FIND  on the NAME variable.

 

Cynthia

 

aaaaa34
Calcite | Level 5
Thanks a lot.
CathyVI
Pyrite | Level 9

Hi,

 

I am using the same find function to identify every "AND" within a string but I am not getting the required result. I have used the sashelp.demographics dataset as an example;

 

data t;
set sashelp.demographics;
new_n=find(isoname,"AND");
if find(isoname,"AND")>0 then output;
run;

 

My aim is to find "and" in the string 'isoname' then create a new variable for all observations with the "and" so i can count them and separate them from observation without "and".

 

For example, In the ISONAME VARIABLE, i want to be able to count variable like "ANTIGUA AND BARBUDA" and keep them in a new variable.

 

 

ANY HELP!

THANKS!

 

PaigeMiller
Diamond | Level 26

I don't have that data set, but the default way SAS operates is that the string "and" is not equal to the string "AND". Could that be the reason you are not getting the expected result?

 

There are many ways to remedy this, one of them is to use the 'i' option of the FIND function, which does the comparison of the text strings ignoring case.

 

if find(isoname,"AND",'i')>0 then output;

 

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1611 views
  • 2 likes
  • 4 in conversation