BookmarkSubscribeRSS Feed
Daen
Calcite | Level 5

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
Daen
Calcite | Level 5

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,'¤');

 

Reeza
Super User

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.


 

Daen
Calcite | Level 5

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?

 

Reeza
Super User

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?

 


 

Tom
Super User Tom
Super User

@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;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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