Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to find row id

Status
Not open for further replies.

Cap2010

Programmer
Mar 29, 2000
196
CA
hi,

How to identify row id in SAS.

select max(rowid) from db.table.

or

select name from db.table where
rowid > db.rowid

Cap2010
 
Cap2010,
When you say RowID what do you mean? Do you nean the row number? In other words what information are you looking for? If its the number of observations there are easier ways. You can use the Proc contents for that info or you could use the attrn function. This function needs to be used with the open/closed functions. Let me know.
Klaz
 
Klaz,

rowid means row number.

want to do calculation on like

select name from db.table where
rowid +1 > db.rowid or

select name from db.table where
rowid = db.rowid+1

Cap2010


 
I have added a field rowid and now it as numbers from
1 to ......

Wanted to delete those records having even numbers how.

tried doing

proc sql;
%let vrowid = 2;
delete * from tt4 where rowid = &vrowid + 2;
quit;

deletes only one record.

cap2010
 
Cap2010,
You seem to like SQL. You can always use the datasep for this type of algorithm and there are many shortcuts that you may use. Since you want the SQL option why not use the following logic.

proc sql;
delete * from tt4 where mod(rowid,2) gt 0;
quit;

This will get you all the even rowid's (since you're deleting the odd rowid's).
Hope this helps you out.
Klaz
 
You can always use a function to determine if the row is odd or even, off the top of my head you want to look up the MOD function which returns the remainder from a division. If you mod your row number with 2 and there is a remainder of 1, then the number is odd, if the result is 0 then the number is even.

Would also recommend not deleting the records but sending them to a separate dataset so as to be able to report on/check the results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top