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

I am trying to import certain columns from MYSQL server and I want to change the format for Datetime fields to 'YYYY-MM-DD HH:MM' and also I need space between column names as the report that uses the data has similar format.

I am trying something like this but seems to ran into error:

PROC SQL;
CONNECT TO xxx AS xxxx (noprompt = "server=xxxxx ;DRIVER=SQL Server;Trusted Connection=yes;DATABASE=xxxx;");
CREATE TABLE X AS
	SELECT * FROM connection to A
	(
	SELECT t1.SAS data1,
		   t1.DateTime format=NLDATMS19. As DueDatetime
	FROM xxx.xxxx as t1
	);
DISCONNECT FROM xxxx;
QUIT;
1 ACCEPTED SOLUTION
7 REPLIES 7
Reeza
Super User
In that nested SELECT query, that needs to be your MYSQL code, not SAS code. So format won't work in that one. I would bring it in raw first, and then reformat on the SAS side, in your select * from connection statement or in a second step.
John04
Fluorite | Level 6
Thanks. I did try that and it seems to work well. The problem that occurs is when I try to schedule it in SAS Management Console, it shows error because of the white space in the column names.
SASKiwi
PROC Star

Please post the SAS log of the scheduled job.

John04
Fluorite | Level 6
The problem is when I try to run it manually, it doesn't show any error. However, when I schedule it in SMC, it doesn't recognize some column names and stops which is why I dont have SAS log.

The error in my log.txt is Column var name could not be found in the table/view identified with the correlation name T1.
Reeza
Super User
Agreed. And my guess is the variable name in the batch would then have underscores instead of the spaces. Or you can add options validvarname=ANY to the top of your program and see what happens.
Reeza
Super User
How are you referring to the variable? I'm guessing you're then running your batch process through a separate install that has slightly different options.

You can refer to it as :

"my variable"n - quotes and N are required.

Example:

proc sql;
select date as "Trading Day"n from sashelp.stocks;
quit;

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 7 replies
  • 1805 views
  • 6 likes
  • 4 in conversation