PROC SQL issue

Occasional Learner
Posts: 1

PROC SQL issue

I have used If first. and last. options in data step. 

But, couldn't find any similar options in proc sql.

Please provide me the solution for this issue.

Trusted Advisor
Posts: 1,799

Re: PROC SQL issue

These options do not exist in PROC SQL.


They exist in DATA steps.


Thus, if you need to use these options, you would use a DATA step and not PROC SQL.

Respected Advisor
Posts: 4,826

Re: PROC SQL issue

  • Conceptually, SQL operates on unordered sets of records. Operations such as first, last, next, previous have no meaning in that context.
  • The DATA step on the other hand operates on a sequence of records. You will sometimes need to sort your data before running the DATA step. 

Use both! You will twice as efficient!

Super User
Posts: 5,391

Re: PROC SQL issue

"Please provide me the solution for this issue"
Yeah, what exactly is your issue?
Syntax itself us never an "issue".
Data never sleeps
Valued Guide
Posts: 2,177

Re: PROC SQL issue

I think the issue is establishing the first and last rows within groups. The limitation of sql was not justified.
The result (finding first. And last. Rows) is native to data steps. My issue is the unexplained constraint (using sql).
But it really is no issue at all.
Respected Advisor
Posts: 4,138

Re: PROC SQL issue

[ Edited ]

I believe @PGStats comment nailed it.

Having said that: Some database SQL extensions provide "first" and "last" as analytics functions ... but then: They don't have the SAS data step and implementing the same with PLSQL can be painful.


Ask a Question
Discussion stats
  • 5 replies
  • 1 like
  • 6 in conversation