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

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
Fluorite | Level 6

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 464 views
  • 1 like
  • 2 in conversation