BookmarkSubscribeRSS Feed
raveena
Obsidian | Level 7

Hi,

Currently am generating the report for the processing month (06/01/2011- 07/01/2011)

and need to select the greatest pidate data from the processing month.

For example,

ID    NAME   PIDATE

1234 david 04/22/2011

3456 roy 07/10/2011

4567 yak 06/15/2011

8976 ron 06/29/2011

9087 don 06/29/2011

From above i need to select a PIDATE within the processing month (06/01/2011- 07/01/2011)

and the greatest pidate value (i.e 06/29/2011)

Output should be,

8976 ron 06/29/2011

9087 don 06/29/2011

Please let me know how to apply this logic by using proc sql.

Thanks in advance.

3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12

Something like this should work (untested code):

SELECT * FROM <data>

WHERE pidate BETWEEN '01jun2011'd AND '30Jun2011'd

AND pidate=(SELECT max(pidate) FROM <data> WHERE pidate BETWEEN '01jun2011'd AND '30Jun2011'd );

A couple of notes:

-- the BETWEEN operator is inclusive, so I modified your dates.

-- this is a correlated subquery, so performance can be poor in large datasets (see documentation).

Doc Muhlbaier

Duke

Howles
Quartz | Level 8

Avoid the correlated subquery

select *

from demo

where pidate BETWEEN '01jun2011'd AND '30Jun2011'd

having pidate EQ max(pidate);

This does employ remerging.

Doc@Duke wrote:

Something like this should work (untested code):

SELECT * FROM <data>

WHERE pidate BETWEEN '01jun2011'd AND '30Jun2011'd

AND pidate=(SELECT max(pidate) FROM <data> WHERE pidate BETWEEN '01jun2011'd AND '30Jun2011'd );

A couple of notes:

-- the BETWEEN operator is inclusive, so I modified your dates.

-- this is a correlated subquery, so performance can be poor in large datasets (see documentation).

Doc Muhlbaier

Duke

raveena
Obsidian | Level 7

Thanks Howles for your help..

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 722 views
  • 0 likes
  • 3 in conversation