BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yudhishtirb
Calcite | Level 5

Hello Team,

 

Greetings

 

I am trying to use below query in one of my program

 

 

proc sql;
create table Emfuleni.RowNumber as
select wGroup, szAccountNumber, Row_Number () over (partition by szAccountNumber order by dtStartGroup asc) as RowNumber
from db.GroupChange
WHERE wClientCode = 100;
quit;

 

But it throwing exception as below 

 

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

 

Can someone please assist me here ?

 

Thanks In advance

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Using just the fields you have shown (and ignoring others like wClientCode):

 

proc sort data=db.GroupChange (keep=sZAccountNumber Amount) out=have;

by sZAccountNumber;

run;

 

data want;

set have;

by sZAccountNumber;

if first.sZAccountNumber then counter = 1;

else counter + 1;

if counter > 2 then delete;

drop counter;

run;

View solution in original post

3 REPLIES 3
Reeza
Super User

This is not valid SAS syntax. 

 

SAS SQL does not have the row_number function. You can try monotonic() in place. 

 

Also, PARTITION is not valid. 

 

You can typically rewrite this using a data step and BY group processing or try a standard group by clause within your SQL.  

yudhishtirb
Calcite | Level 5

HI Reeza,

 

Thanks for feedback. Can you please assist me here ? Following is my input and output required

 

Table :

 

sZaccountNumber Amount

1                            100

2                             400

3                             200

1                             90

1                             300

3                             4000

 

So output must be

1               100

1                90

2               400

3                200

3               4000

 

In short I need to group data by szAccountNumber and only need first 2 rows of that group.

 

Can you please assist me here ? 

 

Thanks In Advance

 

 

Astounding
PROC Star

Using just the fields you have shown (and ignoring others like wClientCode):

 

proc sort data=db.GroupChange (keep=sZAccountNumber Amount) out=have;

by sZAccountNumber;

run;

 

data want;

set have;

by sZAccountNumber;

if first.sZAccountNumber then counter = 1;

else counter + 1;

if counter > 2 then delete;

drop counter;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 13481 views
  • 1 like
  • 3 in conversation