Hi,
What does this function?
find(variable1, "&variable2")>0 or
I saw it in some code online.
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).:
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
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).:
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
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!
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.