Calcite | Level 5

## What does this SAS code mean? Index...

What does

``if index(variable1,'¤') > 0``

mean?

When I do the below, I get values of 0, 8 and 9 for different values of variable1.

``testvar = index(variable1,'¤') > 0;``

Thanks.

5 REPLIES 5
Calcite | Level 5

## Re: What does this SAS code mean? Index...

I meant, I tested the below and got values of 0, 8 and 9 for different values of variable1 with values of 0.6057, 0.0107 and 1E-7 respectively.

``testvar = index(variable1,'¤');``

Super User

## Re: What does this SAS code mean? Index...

Index function: Searches a character expression for a string of characters, and returns the position of the string's first character for the first occurrence of the string.

From your example, variable1 appears numeric. So not sure why it was being used. Or perhaps being used to convert a character variable to numeric and checking for a specific condition that may need to be excluded?

If it's in a conditional statement, anything above 0 is considered TRUE so the remaining code in your condition will execute if that character is found in the string.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/n0vxokxhv8lr84n10nrbnzp7gnba.h...

@Daen wrote:

What does

``if index(variable1,'¤') > 0``

mean?

When I do the below, I get values of 0, 8 and 9 for different values of variable1.

``testvar = index(variable1,'¤') > 0;``

Thanks.

Calcite | Level 5

## Re: What does this SAS code mean? Index...

Any idea what that symbol

``'¤'``

means?

Variable1 is numeric. I thought that symbol might mean, check the number of decimal places, but that didn't seem right with the values obtained?

Super User

## Re: What does this SAS code mean? Index...

Seems like a symbol to me, possibly the character for an invisible white space character or something used as delimiter? Currency symbol? What does the rest of the code look like? With just that line it's very broad guesses.

My random guess is:

• Data was imported using proc import
• this variable was text at some point otherwise using INDEX makes no sense
• this was a step to clean it up the field and convert it to number

@Daen wrote:

Any idea what that symbol

``'¤'``

means?

Variable1 is numeric. I thought that symbol might mean, check the number of decimal places, but that didn't seem right with the values obtained?

Super User

## Re: What does this SAS code mean? Index...

@Daen wrote:

What does

``if index(variable1,'¤') > 0``

mean?

When I do the below, I get values of 0, 8 and 9 for different values of variable1.

``testvar = index(variable1,'¤') > 0;``

Thanks.

There is no way that TESTVAR could ever get a value other than 0 or 1 from that statement.  SAS evaluates boolean expressions. like your test if the result of the INDEX() function call is larger than 0, as 1 when TRUE and 0 when FALSE.

The INDEX() function returns the location in the string string of the start of the second string. If it is not found it returns zero.

The character you posted is the character A4 in Latin1 encoding.

 ¤ A4 ¤ ¤ general currency sign

But in EBCDIC it is a lower case U.

If variable1 is numeric you should get notes about SAS converting it to a string so it could be passed to the INDEX() function and the value of TESTVAR will always be set to zero since the string SAS will create from a numeric variable will never contain that character, whatever it is.

PS When coding string literals that have characters that are not between a space and tilda in the ASCII code sequence you might want to use hex literals instead to avoid issues when the encoding changes.

``testvar = index(variable1,'A4'x) > 0;``

Discussion stats
• 5 replies
• 471 views
• 0 likes
• 3 in conversation