Date: Fri, 26 May 2006 15:58:56 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: dates and merging
In-Reply-To: <200605261538.k4QFBLBF032625@mailgw.cc.uga.edu>
Content-Type: text/plain; format=flowed
Kateri ,
That would depend on what form the date sare in to begin with. If both are
already in SAS Date/Time format then I suspect there wouldnt be a problem
but their could be if one is a SAS Date value and the other is a DateTime
value. If you have the case that one is a SAS Date or DateTime value and
the other is not then you will have to convert the date that isnt to a SAS
Date or DateTime value so long as the SAS Date time value is the same as the
other Variable. If neither is a SAS date time value I would suggest
converting them into a SAS Date or DateTime value which ever is appropriate.
So just how do you convert a character value which represents a Date or Date
Time value to a SAS Date or Date Time value:
Data _null_ ;
/** Input function requires a valid SAS Informat **/
Date = input( '01JAN2006' , Date9. ) ;
DateTime = input( '01JAN2006:12:30:00' , DateTime18. ) ;
Time = input( '12:30:00' , Time8. ) ;
/** Put Function Requires a Valid SAS Format **/
Date2 = put( Date , Date9. ) ;
DateTime2 = put( DateTime , DateTime18. ) ;
Time2 = put( Time , Time8. ) ;
Put Date= Date2=
Datetime= DateTime2=
Time= Time2= ;
run ;
Here I used Date, DateTime, and Time literals (ie. '01Jan2006'd etc...) but
you can just as easily use a variable that contains the character value that
needs to be converted.
Data _null_ ;
CharDate = '01Jan2006' ;
SASDate = input( CharDate , Date9. ) ;
put CharDate= SASDate= ;
run ;
Two important things to remember: First you use input to convert from a
character to a numeric and put function to convert from a numeric to a
character. Secondly you can convert any character or numeric so long as you
use a valid SAS informat or format respectively.
Toby Dunn
From: Kateri Heydon <heydon@EMAIL.CHOP.EDU>
Reply-To: Kateri Heydon <heydon@EMAIL.CHOP.EDU>
To: SAS-L@LISTSERV.UGA.EDU
Subject: dates and merging
Date: Fri, 26 May 2006 11:38:41 -0400
Hi--
I am having a problem with dates in SAS. I have 2 datasets, one was
created in excel. I am trying to merge the 2 datasets by a field that is
contained in both datasets "visit_date". Even if the 2 fields match, SAS
is not recognizing some of the observations. How do I format the dates, in
sas, to be read the same way?