Write system date and time as string to gdx - gams-math

I want to store the system date and time as a string to gdx when executing a script, preferably with a custom format.
I tried the following:
parameter
exec_date execution date
exec_time execution time
;
exec_date = '%system.date1%';
exec_time = '%system.time%';
However I get the following error message in the .lst file:
1 parameter
2 exec_date execution date
3 exec_time execution time
4 ;
5
6 exec_date = 'Dec 17, 2020';
**** $119,140,409
**** 119 Number (primary) expected
**** 140 Unknown symbol
**** 409 Unrecognizable item - skip to find a new statement
**** looking for a ';' or a key word to get started again
7 exec_time = '13:24:05';
**** $119,409
**** 119 Number (primary) expected
**** 409 Unrecognizable item - skip to find a new statement
**** looking for a ';' or a key word to get started again
The following snippet gives the same error message:
variable
exec_date execution date
exec_time execution time
;
exec_date = '%system.date1%';
exec_time = '%system.time%';
Finally, the following snippet runs without error:
$set exec_date = '%system.date1%';
$set exec_time = '%system.time%';
However it seems that both exec_date and exec_time are not dumped to gdx:
gams date gdx=date
Moreover, I tried to display exec_date and exec_time:
display
exec_date
exec_time;
However, I get the following error message in the .lst file:
21 display
22 exec_date
**** $140
**** 140 Unknown symbol
23 exec_time;
**** $140
**** 140 Unknown symbol
Is it possible to store the system date and time as a string to gdx?
Moreover, is it possible to format the date string as yyyy-mm-dd?

It can be implemented as set:
set
exec_date /'%system.date%'/
exec_time /'%system.time%'/
;
display
exec_date
exec_time
;
This outputs:
---- 31 SET exec_date
12/17/20
---- 31 SET exec_time
15:32:46
And is saved to gdx using
gams date gdx=date

Related

How to insert by select?

There is a CREATE TABLE t1 (a int, b int, x string), and the instruction SELECT 1 a, 2 b, 'hello' x; is valid, so I expected that it is not an error:
INSERT INTO my_db.t1 SELECT 1 a, 2 b, 'hello' x;
-- OR
INSERT INTO my_db.t1 SELECT a, b, x FROM t2;
Why it is an error? ... Or it is a bug?
Error: Error while compiling statement: FAILED: ParseException line 1:40 Failed to recognize predicate ''. Failed rule: 'regularBody' in statement (state=42000,code=40000)
NOTES.
Also tested INSERT OVERWRITE TABLE my_db.t1 PARTITION(x) SELECT ... when used t with partition... but same error.
Seems why does inserting record into hive fails with FailedPredicateException? but in my case it not works also with SELECT FROM.
Hive version seems 1.2... hive --version say
2021-03-26 09:22:44,840 DEBUG [main] util.HiveVersionInfo: version: #org.apache.hive.common.HiveVersionAnnotation(version=1.2.1000.2.6.4.0-91, shortVersion=1.2.1000, revision=87f2bc04724e559819902a574e78b2beeaf9f541, branch=(detached from 87f2bc0), user=jenkins, date=Thu Jan 4 10:47:01 UTC 2018, url=git://ctr-e134-1499953498516-209689-01-000004.hwx.site/grid/0/jenkins/workspace/HDP-parallel-centos7/SOURCES/hive, srcChecksum=73af1d20b2f8a15f36ac132297e70386)
Hive 1.2.1000.2.6.4.0-91
Subversion git://ctr-e134-1499953498516-209689-01-000004.hwx.site/grid/0/jenkins/workspace/HDP-parallel-centos7/SOURCES/hive -r 87f2bc04724e559819902a574e78b2beeaf9f541
Compiled by jenkins on Thu Jan 4 10:47:01 UTC 2018
From source with checksum 73af1d20b2f8a15f36ac132297e70386
2021-03-26 09:22:45,177 DEBUG [Thread-0] util.ShutdownHookManager: ShutdownHookManger complete shutdown.

SAS YYMMDD10. works but YYMMDDn10 doesn't

This is my data (sorry for no script, it's just proc create table from mssql):
testdb.testtable
id - numeric
date_from - numeric (datetime from mssql)
date_to - numeric (datetime from mssql)
base_id - numeric
base_id2 - string (length 64)
What I tried to do was:
proc sql;
update testdb.testtable tt
set base_id2 = CATX('_',
('data from other table'),
put(datepart(date_from),yymmddn10.),
put(datepart(date_to),yymmddn10.),
put(base_id,z4.)
)
where (....)
;
quit;
And I get this error:
The width value for YYMMDDN is out of bounds. It should be between 2 and 8.
The width value for YYMMDDN is out of bounds. It should be between 2 and 8.
What I really don't understand is that when I use format with separators, YYMMDD10., it works.
When i run:
proc sql;
select datepart(date_from) format=yymmddn10. from testdb.testtable;
quit;
It returns 20191227 - It's great. When I run
proc sql;
select put(datepart(date_from),yymmddn10.) from testdb.testtable;
quit;
It fails with the same error.
What do I miss?
There seems to be a bug in PROC SQL that allows you to attach a format that cannot work (the maximum width needed for a date without separators is 8 bytes).
It is also interesting that PROC PRINT (and the simple SELECT query in PROC SQL, like in your example) do not mind that the format width is invalid.
542 data test1;
543 now=date();
544 run;
NOTE: The data set WORK.TEST1 has 1 observations and 1 variables.
545
546 data test2 ;
547 set test1;
548 format now yymmddn10.;
----------
29
ERROR 29-185: Width specified for format YYMMDDN is invalid.
549 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST2 may be incomplete. When this step was stopped there were 0 observations
and 1 variables.
WARNING: Data set WORK.TEST2 was not replaced because this step was stopped.
550
551 proc sql;
552 create table test2 as select now format=yymmddn10. from test1;
NOTE: Table WORK.TEST2 created, with 1 rows and 1 columns.
553 select * from test2;
554 quit;
555
556 proc print data=test2;
557 run;
NOTE: There were 1 observations read from the data set WORK.TEST2.
558
559 data test3;
560 set test2;
561 run;
ERROR: Width specified for format YYMMDDN is invalid.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST3 may be incomplete. When this step was stopped there were 0 observations
and 1 variables.
WARNING: Data set WORK.TEST3 was not replaced because this step was stopped.
Also interesting is that if you use that format specification in PROC FREQ
proc freq data=test2; tables now; run;
it adds a space and a 'F7'x character in front of the data string.
The FREQ Procedure
Cumulative Cumulative
now Frequency Percent Frequency Percent
---------------------------------------------------------------
รท20200218 1 100.00 1 100.00
The number in format is the given width. Format YYMMDDn has 8 chars, so I should have used YYMMDDn8. And it worked.
I was having a long struggle with it and I still don't understand why did it work in format= and not in put().

Using variable in Oracle function

I have a variable and want to use in a query inside fuzzy function but it is giving me some syntax error or wrong result considering the var.
ORA-20000: Oracle Text error:
DRG-50901: text query parser syntax error on line 1, column 21 29902.
00000 - "error in executing ODCIIndexStart() routine"
When I replace the my_var variable in the fuzzy function with some static string it works fine but with variable it is giving me this error.
My query is as follows:
DEFINE my_var = 'Bhularam';
SELECT a.EXTERNALID_ENC,
a.EXTERNALID,
a.TELNUMBER,
a.TELAREACODE,
a.DQ_ENGLISH_NAME,
a.DQ_ARABIC_NAME,
a.NAMEFIELD_1,
a.USAGETYPE,
a.MANUAL_UPDATE_FLAG,
a.RULE_UPDATE_FLAG,
a.BUSINESS_UPDATE_FLAG,
a.EXCEL_UPDATE_FLAG
FROM (
SELECT * FROM (
SELECT dqlist.*,
score(1) AS rank
FROM dq_list_hash_full dqlist
WHERE contains(dqlist.dq_english_name
,'definescore(fuzzy(my_var, 1, 6, weight),relevance)',1) > 0
UNION
SELECT
dqlist.*,
score(1) AS rank
FROM
dq_list_hash_full dqlist
WHERE
contains(dqlist.dq_english_name,'!Bhularam',1) > 0
)
ORDER BY
rank DESC
) a
I know it is something really stupid but I am unable to get my head around it probably I am new to oracle. Please help me out.
If using sqlplus, verify what prefix character is used to identify substitution variables. Default is set to '&'.
sqlplus > show define
define "&" (hex 26)
Try using your substitution variable within your query, for example
sqlplus > define my_var='hello world!'
sqlplus > select '&my_var' from dual;
old 1: select '&my_var' from dual
new 1: select 'hello world!' from dual
'HELLOWORLD!'
--------------------------------
hello world!
For your query try (assuming define is set to '&'):
'definescore(fuzzy(&my_var, 1, 6, weight),relevance)',1)

`FOR UPDATE` breaks batch execution in HANA

HANA 102.05 fails to execute the following code:
CREATE TABLE ATABLE( f INT );
CREATE PROCEDURE TestProc()
AS
BEGIN
SELECT f FROM ATABLE
FOR UPDATE; -- Without FOR UPDATE it works
END;
SELECT 'Hello' FROM DUMMY;
complaining that:
SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "SELECT": line 8 col 2 (at pos 124)
which points outside the proceudure, at SELECT 'Hello'. The procedure itself compiles without error. The entire script completes successfully if I remove the FOR UPDATE directive. What is wrong with the original?
Update
When I execute the same query from hdbsql.exe I get:
0 rows affected (overall time 26,076 msec; server time 6518 usec)
* 257: sql syntax error: line 5 col 9 (at pos 71) SQLSTATE: HY000
* 257: sql syntax error: incorrect syntax near "END": line 2 col 1 (at pos 32) SQLSTATE: HY000
'Hello'
"Hello"
1 row selected (overall time 4644 usec; server time 143 usec)

SQL sub queries error

select(select SUM(HOME_SCORE) total from MATCH )
+
(select SUM(AWAY_SCORE) total from MATCH)
as "GOALS SCORED"
From dual ;
this is meant to return the sum of HOME_SCORE and AWAY_SCORE I get the following error
Error starting at line : 242 in command -
select(select SUM(HOME_SCORE) total from MATCH )
Error report -
Unknown Command
Error starting at line : 243 in command -
+
Error report -
Unknown Command
Query Run In:Query Result
Maybe your lacking in parenthesis if you want that way please rewrite your script to this select((select SUM(HOME_SCORE) total from MATCH )
+
(select SUM(AWAY_SCORE) total from MATCH))
as "GOALS SCORED"
From dual ;
or to simplify this you can try this select(select SUM(HOME_SCORE) + SUM(AWAY_SCORE) total from MATCH )
as "GOALS SCORED"
From dual ;