From: Sdlentertd on 18 Feb 2010 11:22 I am looking to convert a date to this in order to merge with another table: Rxa_date Numeric, Length 8, Format 11. and looks like 20100214 I have 2 fields in another table that are dof_date1 and dof_date2: If one of them is populated then it is Numeric, Length 8, Format MMDDYY10. , and looks like 02/14/2010. if the other field is not populated then it is character, Length 1, Format $1. I am trying to make dof_date1 and dof_date2 consistant so it matches to Rxa_date . In the beginning the dataset looks like this: Number dof_date1 dof_date1 22 02/14/2010 Later it looks like this Number dof 22 02/14/2010 22 I want it to look like this Number dof 22 20100214 (Numeric, Length 8, Format 11. ) 22 . Here is what I did to make sure the formats match wether date is missing or not if dof_date1 = '' then do; Rxa_date = input (Date dof_date1 , DATE9.) ; END; else DO; FORMAT Rxa_date 11.; Rxa_date = dof_date1 ; END; But it doesnt quit work because the date Rxa_date that I get is Numeric, Length 8, Format 11 and it looks like 18302 and not 20100214 Thank you
From: Tom Abernathy on 18 Feb 2010 12:16 Not sure what you are talking about with the second variable so I will ignore it. To convert a SAS date to a number that just happens to look like a date you can use PUT to generate an 8 digit character string and then INPUT to convert that character string into a number. Like this: rxa_date = input(put(dof_date1,yymmddn8.),8.); format rxa_date 11.; - Tom On Feb 18, 11:22 am, Sdlentertd <sdlente...(a)gmail.com> wrote: > I am looking to convert a date to this in order to merge with another > table: > Rxa_date Numeric, Length 8, Format 11. and looks like 20100214 > > I have 2 fields in another table that are dof_date1 and dof_date2: > If one of them is populated then it is Numeric, Length 8, Format > MMDDYY10. , and looks like 02/14/2010. if the other field is not > populated then it is character, Length 1, Format $1. > > I am trying to make dof_date1 and dof_date2 consistant so it matches > to Rxa_date . > > In the beginning the dataset looks like this: > Number dof_date1 dof_date1 > 22 02/14/2010 > > Later it looks like this > Number dof > 22 02/14/2010 > 22 > I want it to look like this > Number dof > 22 20100214 (Numeric, Length 8, Format 11. ) > 22 . > > Here is what I did to make sure the formats match wether date is > missing or not > if dof_date1 = '' then do; > Rxa_date = input (Date dof_date1 , DATE9.) ; END; > else DO; FORMAT Rxa_date 11.; Rxa_date = dof_date1 ; END; > > But it doesnt quit work because the date Rxa_date that I get is > Numeric, Length 8, Format 11 and it looks like 18302 and not > 20100214 > > Thank you
From: Sdlentertd on 18 Feb 2010 12:44 On Feb 18, 10:16 am, Tom Abernathy <tom.aberna...(a)gmail.com> wrote: > Not sure what you are talking about with the second variable so I will > ignore it. > To convert a SAS date to a number that just happens to look like a > date you can use PUT to generate an 8 digit character string and then > INPUT to convert that character string into a number. > Like this: > > rxa_date = input(put(dof_date1,yymmddn8.),8.); > format rxa_date 11.; > > - Tom > > On Feb 18, 11:22 am, Sdlentertd <sdlente...(a)gmail.com> wrote: > > > > > I am looking to convert a date to this in order to merge with another > > table: > > Rxa_date Numeric, Length 8, Format 11. and looks like 20100214 > > > I have 2 fields in another table that are dof_date1 and dof_date2: > > If one of them is populated then it is Numeric, Length 8, Format > > MMDDYY10. , and looks like 02/14/2010. if the other field is not > > populated then it is character, Length 1, Format $1. > > > I am trying to make dof_date1 and dof_date2 consistant so it matches > > to Rxa_date . > > > In the beginning the dataset looks like this: > > Number dof_date1 dof_date1 > > 22 02/14/2010 > > > Later it looks like this > > Number dof > > 22 02/14/2010 > > 22 > > I want it to look like this > > Number dof > > 22 20100214 (Numeric, Length 8, Format 11. ) > > 22 . > > > Here is what I did to make sure the formats match wether date is > > missing or not > > if dof_date1 = '' then do; > > Rxa_date = input (Date dof_date1 , DATE9.) ; END; > > else DO; FORMAT Rxa_date 11.; Rxa_date = dof_date1 ; END; > > > But it doesnt quit work because the date Rxa_date that I get is > > Numeric, Length 8, Format 11 and it looks like 18302 and not > > 20100214 > > > Thank you- Hide quoted text - > > - Show quoted text - It doesn't work, the date still shows up as 18302 so what i need is for the date to look like this Numeric, Length 8, Format 11. and looks like 20100214 but the trick is the date field can be numeric and populated or character and blanc (only these 2 scenarios)
From: Tom Abernathy on 18 Feb 2010 13:02 Try again. Works fine for me. data _null_; datevar=18302; numvar=input(put(datevar,yymmddn8.),8.); put datevar= 'Formated YYMMDDN8.=' datevar yymmddn8. +1 numvar=; run; datevar=18302 Formated YYMMDDN8.=20100209 numvar=20100209 On Feb 18, 12:44 pm, Sdlentertd <sdlente...(a)gmail.com> wrote: > On Feb 18, 10:16 am, Tom Abernathy <tom.aberna...(a)gmail.com> wrote: > > > > > > > Not sure what you are talking about with the second variable so I will > > ignore it. > > To convert a SAS date to a number that just happens to look like a > > date you can use PUT to generate an 8 digit character string and then > > INPUT to convert that character string into a number. > > Like this: > > > rxa_date = input(put(dof_date1,yymmddn8.),8.); > > format rxa_date 11.; > > > - Tom > > > On Feb 18, 11:22 am, Sdlentertd <sdlente...(a)gmail.com> wrote: > > > > I am looking to convert a date to this in order to merge with another > > > table: > > > Rxa_date Numeric, Length 8, Format 11. and looks like 20100214 > > > > I have 2 fields in another table that are dof_date1 and dof_date2: > > > If one of them is populated then it is Numeric, Length 8, Format > > > MMDDYY10. , and looks like 02/14/2010. if the other field is not > > > populated then it is character, Length 1, Format $1. > > > > I am trying to make dof_date1 and dof_date2 consistant so it matches > > > to Rxa_date . > > > > In the beginning the dataset looks like this: > > > Number dof_date1 dof_date1 > > > 22 02/14/2010 > > > > Later it looks like this > > > Number dof > > > 22 02/14/2010 > > > 22 > > > I want it to look like this > > > Number dof > > > 22 20100214 (Numeric, Length 8, Format 11. ) > > > 22 . > > > > Here is what I did to make sure the formats match wether date is > > > missing or not > > > if dof_date1 = '' then do; > > > Rxa_date = input (Date dof_date1 , DATE9.) ; END; > > > else DO; FORMAT Rxa_date 11.; Rxa_date = dof_date1 ; END; > > > > But it doesnt quit work because the date Rxa_date that I get is > > > Numeric, Length 8, Format 11 and it looks like 18302 and not > > > 20100214 > > > > Thank you- Hide quoted text - > > > - Show quoted text - > > It doesn't work, the date still shows up as 18302 > so what i need is for the date to look like this Numeric, Length 8, > Format 11. and looks like 20100214 > but the trick is the date field can be numeric and populated or > character and blanc (only these 2 scenarios)- Hide quoted text - > > - Show quoted text -
From: Sdlentertd on 18 Feb 2010 13:16 On Feb 18, 9:22 am, Sdlentertd <sdlente...(a)gmail.com> wrote: > I am looking to convert a date to this in order to merge with another > table: > Rxa_date Numeric, Length 8, Format 11. and looks like 20100214 > > I have 2 fields in another table that are dof_date1 and dof_date2: > If one of them is populated then it is Numeric, Length 8, Format > MMDDYY10. , and looks like 02/14/2010. if the other field is not > populated then it is character, Length 1, Format $1. > > I am trying to make dof_date1 and dof_date2 consistant so it matches > to Rxa_date . > > In the beginning the dataset looks like this: > Number dof_date1 dof_date1 > 22 02/14/2010 > > Later it looks like this > Number dof > 22 02/14/2010 > 22 > I want it to look like this > Number dof > 22 20100214 (Numeric, Length 8, Format 11. ) > 22 . > > Here is what I did to make sure the formats match wether date is > missing or not > if dof_date1 = '' then do; > Rxa_date = input (Date dof_date1 , DATE9.) ; END; > else DO; FORMAT Rxa_date 11.; Rxa_date = dof_date1 ; END; > > But it doesnt quit work because the date Rxa_date that I get is > Numeric, Length 8, Format 11 and it looks like 18302 and not > 20100214 > > Thank you Yes, it worked Thank you... but I noticed that sometimes the field can be numeric and then the formula doesn't work because I need to do if -then for two cases: populated numeric or blank character . The end results houdl be Numeric, Length 8, Format 11 (20100214) or blank Numeric, Length 8, Format 11 (for merger later)
|
Next
|
Last
Pages: 1 2 Prev: Convert Character into numeric Next: Convert to numeric where Date field Numeric and Character |