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!

Get a first occurrence in a query

Status
Not open for further replies.

dbdinc

MIS
Apr 13, 2007
58
US
In a sotred process being coded in EG, is there a way, in a query, to obtain the first occurrence of a data field? Something like the following pseudocode....

Create table suchandsuch;
first requestedfield
fieldb
fieldc
first fieldd
quit;
run;

In short, say I have 10 occurrences of a record (no, not duplicates) for Joe Schmoe, but I only want to gather info for the first occurrence. I know how to do this in MS Access queries, but haven't seen anything about it for stored processes.
 
Use a datastep with by group processing.
Code:
data suchandsuch;
  set mydata;
  by person_id;

  if first.person_id then output suchandsuch;
run;
Should do the job for you.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thanks, Chris,

I already got that solution from other sources, but do appreciate you replying. I jusdt couldn't wait several days and therefore researched other sources of information.
 
No worries, I've been on holiday in Peru. :)

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
How nice! Hope you enjoyed Peru. My wife and I are thining of Ecuador and Galapagos next year. Have you been there? If so, what is a good way to see the Galapagos?
 
Nah, just Peru.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top