BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
phongpham
Obsidian | Level 7

Hi Mates,

I am trying to convert numeric date type column to YYMMDDD10.  format using datepart. But when I try this command, it always give me the value of " 1960-01-01" which is not the correct date. I just wonder if you can help me figuring out what wrong with it. 

Here is the data:

phongpham_0-1630702920503.png

and here is the code:

proc sql; /* why I can't convert date1 to correct date */
	create table z_raw_final as
		select date1, datepart(date1) 			as d_mth format YYMMDDD10.  
				, n_quarter
				, gdp_base
				, retail_sales_base 	as rto_base 
				, ICR_base
				, business_credit_base 	as bcg_base
		from z_raw1
		 	where n_quarter > -41 and n_quarter <= 20  ;
	quit;

I also try another way that I found in this forum but just get NULL values

data z_raw_final;
set z_raw_final;
format date1 datetime20.;
run;

Thanks for your help!

 

Phong Pham

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Excel dates need to be converted to SAS dates via the method shown here: https://communities.sas.com/t5/New-SAS-User/Numeric-dates-not-converted-to-dates-properly/m-p/708873

 

Also, DATEPART() is not needed once you do the above conversion.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Excel dates need to be converted to SAS dates via the method shown here: https://communities.sas.com/t5/New-SAS-User/Numeric-dates-not-converted-to-dates-properly/m-p/708873

 

Also, DATEPART() is not needed once you do the above conversion.

--
Paige Miller
phongpham
Obsidian | Level 7

Thanks @PaigeMiller . I understand now. Just fixed my code and it works well. Very much appreciate your help. 🙂