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 (December 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 3 Dec 2005 19:06:27 +0000
Reply-To:     iw1junk@COMCAST.NET
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1junk@COMCAST.NET>
Subject:      Better syntax for creating subset of data
Comments: cc: Hari <excel_hari@YAHOO.COM>

Hari, It would be a good idea to learn how SAS stores dates and manipulates dates. You might start by looking at dates and times in the concepts section of the help files. You will learn a lot about functions and formats on the way. The following code illustrates your problem (assuming I have interpreted the dates correctly). data w ; format date date9. ; input orig $char9. ; /* make corresponding SAS date */ date = input ( compress(substr(orig,4,2)||substr(orig,1,3) ||substr(orig,6,2)) , date9. ) ; /* subsetting IF */ if "27sep2003"d < date < "01oct2005"d ; cards ; sep1303.1 sep2003.1 sep2703.1 oct0403.1 sep2405.1 oct0105.1 oct0805.1 oct1505.1 oct2205.1 oct2905.1 ; The line constructing DATE may look worse than the problem, but consider it the cost of not having a SAS date in the first place. I didn't know how to interpret the .1 so I just ignored it. Better syntax for your character data might be if per not in ( "SEP1303.1" "SEP2003.1" ... ) ; but I do not think it is the right solution. Learning SAS dates is essential. Ian Whitlock =============== Date: Sat, 3 Dec 2005 02:53:22 -0800 Reply-To: Hari <excel_hari@YAHOO.COM> Sender: "SAS(r) Discussion" From: Hari <excel_hari@YAHOO.COM> Organization: http://groups.google.com Subject: Better syntax for creating subset of data Comments: To: sas-l Content-Type: text/plain; charset="iso-8859-1" Hi, I have a variable called Per which contains week for which data is relevant. The week data is in string format like "SEP2703.1" etc. There are 112 observations for as many weeks. I want to keep data only for 104 weeks. So, I wrote the following code:- data Total104WeeksOnly; Set RawTotal112Weeks; if (per ^= "SEP1303.1") and (per ^= "SEP2003.1") and (per ^= "SEP2703.1") and (per ^= "OCT0105.1") and (per ^= "OCT0805.1") and (per ^= "OCT1505.1") and (per ^= "OCT2205.1") and (per ^= "OCT2905.1"); run; Are there better ways to achieve what I have done above? For example, I am forced to write the NOT comparison for Per variable 8 times. One way might be to use an array which holds the above 8 Per values (what would be the correct syntax for using arrays here). Also would like to know if more polished methods exist. Regards, Hari India


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