LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2009, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 9 Jun 2009 19:17:55 +0530
Reply-To:     mahesh kumar peesari <peesari.mahesh@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         mahesh kumar peesari <peesari.mahesh@GMAIL.COM>
Subject:      Re: first. problem while fetching records..
Comments: To: "Richard A. DeVenezia" <rdevenezia@wildblue.net>
In-Reply-To:  <8e83cde0-8fa0-4b8d-8dc7-4fe2567dda63@e24g2000vbe.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

HI Richard, thanks,a lot.I have modified little bit of code.

proc sort data=Examples.final_aggrgtd1; by plant lptno oadcredt; run;

Libname Examples 'E:\Homework\Examples'; data firstparts11; set Examples.final_aggrgtd1; by plant LPTNO; if first.lptno and put(oadcredt,monyy7.)='APR2003'; run;

proc sort data=firstparts; by oadcredt lptno plant; run;

i am creating a dataset corresponding to date= APR2003,still here its fine,but if i select a particular part from APR2003 and run this query, proc sql; select * from final_aggrgtd1 where part='A01'; quit;

i get o/p from previous years also corresponding to that particular part. but my concern is i want those parts which are not present in previous years i,e parts which are not ordered previously and new order has been raised for that particular part... how should i try get only records starting from that particular monthyear till end .

Thanks IN advance.

On Tue, Jun 9, 2009 at 5:58 PM, Richard A. DeVenezia < rdevenezia@wildblue.net> wrote:

> On Jun 9, 6:39 am, peesari.mah...@GMAIL.COM ("SUBSCRIBE SAS-L Joe H. > Smith") wrote: > > hi all; > > > > this is my dataset, > > plant date part demand > > A01 apr2001 ax1 23 > > A02 apr2001 ax1 34 > > A01 apr2001 ax2 43 > > A03 apr2001 ax3 53 > > A01 may2001 ax1 32 > > A02 may2001 ax2 54 > > A05 may2001 ax8 87 > > > > if i am using this code > > > > data test; > > set try; > > by part; > > if FIRST.part =1 and put(date,monyy7.)='APR2001'; > > run; > > > > i am getting this output > > > > plant date part demand > > A01 apr2001 ax1 23 > > A01 apr2001 ax2 43 > > A03 apr2001 ax3 53 > > > > actually i am looking for all the parts that have been ordered for > > apr2001,irrespective of plant. > > > > my desired o/p should be this way-- > > > > plant date part demand > > A01 apr2001 ax1 23 > > A02 apr2001 ax2 34 > > A03 apr2001 ax3 53 > > A01 apr2001 ax2 43 > > > > data test; > > set try; > > if put(date,monyy7.)='APR2001'; > > run; > > > > if i use the above code-i can directly get all the parts orderred in > > apr2001,it works fine for apr2001,but when i use may2001 it fetches all > the > > records which i am not intrested ,i want records of only those parts that > > are ordered in month 0f may2001 > > > > if i run this code > > > > data test; > > set try; > > if put(date,monyy7.)='MAY2001'; > > run; > > > > i get this o/p : > > > > A01 may2001 ax1 32 > > A02 may2001 ax2 54 > > A05 may2001 ax8 87 > > > > i am not intrested in above o/p i need o/p this way > > > > A02 may2001 ax2 54 > > A05 may2001 ax8 87 > > > > i dont need part ax1 as it is already ordered in apr2001, > > and its not a new order in the month of may2001. > > i want only those parts which are newly ordered for that particular > > month(may2001) on various plants. > > > > i can use first.,but it will fetch me only those records for the first > > time,in my case if i use first.part=1 ,it gives all records that are > > ordered for time in apr2001,it wont consider the plant,i want to even > > consider demand for the first time on plant and part. > > > > may be i am confusing a lot .. > > please give inputs to fetch only those new records ordeered for > particular > > part on that monthyear. > > > > Thanks a lot, > > Joe: > > You want the first row in each plant part bygroup (sorted by date). > > Here are two ways to do this. The first uses the data in the > presented order (appears to be sorted by date part plant) and a hash > to track prior outputs (for criteria test for not outputting later > records). The second uses a multi-step process to sort select and > resort. > > -------------------------------------------- > data orders; > input > plant $ date: monyy7. part $ demand ; > format date monyy7.; > datalines; > A01 apr2001 ax1 23 > A02 apr2001 ax1 34 > A01 apr2001 ax2 43 > A03 apr2001 ax3 53 > A01 may2001 ax1 32 > A02 may2001 ax2 54 > A05 may2001 ax8 87 > run; > > * one way; > > data firstparts(label='First ordered parts by per plant'); > > if _n_ = 1 then do; > declare hash PastOrders(); > PastOrders.defineKey('plant','part'); > PastOrders.defineDone(); > end; > > set orders; > > if PastOrders.check() ne 0; > PastOrders.add(); > run; > > * a second way; > > proc sort data=orders; > by plant part date; > run; > > data firstparts2; > set orders; > by plant part; > if first.part; > run; > > proc sort data=firstparts2; > by date part plant; > run; > -------------------------------------------- > > Richard A. DeVenezia > http://www.devenezia.com >

-- Jack Of All Trades....But Master Of NONE....


Back to: Top of message | Previous page | Main SAS-L page