LOC Function
Returns the row number in which the given value is found in the given column.
| Category: | Result Tables |
|---|---|
| Returned data type: | Returns the value of -1 when the value is not found, otherwise returns the row number. |
Table of Contents
Syntax
Required Arguments
table-name
The name of the table from which the row value is retrieved.
column
The column can be can be a number or a character value.
value
The value to search for in the table. The value can be a character or numeric value.
Example: Using the LOC Function
The following example demonstrates how to use the LOC function to retrieve a row number for a specified value of 75000.
proc casutil;
load data=sashelp.cars
casout="cars"
outcaslib="casuser"
replace;
run;
proc cas;
table.fetch result=r/ table="cars" to=428;
findcar=sort_rev(findtable(r), "Invoice")[1:25, {"Make", "Model", "Type", "DriveTrain" "MSRP", "Invoice"}];
y=loc(findcar, "MSRP", 75000);
print "The row in which the value appears is= " y;
run;
SAS Log
The row in which the value appears is= 18
Last updated: August 18, 2026