BookmarkSubscribeRSS Feed
jflycn
Calcite | Level 5
ROW_NUMBER is a reserved word in FedSQL (See: http://support.sas.com/documentation/cdl/en/fedsqlref/67364/HTML/default/p0x0k1rlx0l7e4n1ptngog3ce4j... ), but I cannot figure out how to use ROW_NUMBER in it. Whatever I tried, I always got "ERROR: Syntax error at or near "ROW_NUMBER"".

So how can I use ROW_NUMBER in FedSQL?
 
Thanks!
7 REPLIES 7
kannand
Lapis Lazuli | Level 10

The documentation indicated the use of double quotes while using a reserved word for other purposes.   I've tried out in this example below:

 

PROC FEDSQL;
DROP TABLE WORK.T1;
create table T1
   ( "ROW_NUMBER" CHAR(2),
     name char(10),
     state char(2));
DESCRIBE TABLE WORK.T1;
SELECT  * FROM DICTIONARY.COLUMNS WHERE TABLE_NAME = 'T1';
QUIT;

The results are shown below for your reference:

 


TABLE_CAT	TABLE_SCHEM	TABLE_NAME	COLUMN_NAME	DATA_TYPE	TYPE_NAME	COLUMN_SIZE	BUFFER_LENGTH	DECIMAL_DIGITS	NUM_PREC_RADIX	NULLABLE	REMARKS	COLUMN_DEF	TKTS_DATA_TYPE	TKTS_DATETIME_SUB	CHAR_OCTET_LENGTH	ORDINAL_POSITION	IS_NULLABLE
WORK	WORK	T1	ROW_NUMBER	-8	NCHAR	2	3	.	.	1	 	 	-8	.	2	1	YES
WORK	WORK	T1	NAME	-8	NCHAR	10	11	.	.	1	 	 	-8	.	10	2	YES
WORK	WORK	T1	STATE	-8	NCHAR	2	3	.	.	1	 	 	-8	.	2	3	YES

The header has shifter a bit but have highlighted in red for ease of reading... Hope this helps.... Good Luck...!!!

Kannan Deivasigamani
jflycn
Calcite | Level 5

Hi Kannan, thanks for your answer, but I think I did not state my question clear enough. What I meant is to use ROW_NUMBER as it really meant to be, i.e. as a function of retreving row number(e.g. https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions144.htm ).

 

I tried to use ROW_NUMBER to get row number but it did not work.

kannand
Lapis Lazuli | Level 10

I believe the documentation states that the FEDSQL RESERVED words cannot be used as variable names or in any other way as indicated in the document below:

 

https://support.sas.com/documentation/cdl/en/fedsqlref/67954/HTML/default/viewer.htm#p0x0k1rlx0l7e4n...

 

The documentation you provided in your URL refers to the ROW_NUMBER feature in ORACLE database. This is one among those nuiances between the two softwares that seems identical but not really so.  

 

  https://support.sas.com/documentation/cdl/en/fedsqlref/67954/HTML/default/viewer.htm#p0x0k1rlx0l7e4n...

 

Hope this clarifies your conundrum.... Good Luck...!!!

Kannan Deivasigamani
jflycn
Calcite | Level 5

I can totally understand if SAS FedSQL misses a function which Oracle SQL has. I am just curious since FedSQL already makes ROW_NUMBER  a reserved word, I guess there might be a way of using ROW_NUMBER to retrieve row number in FedSQL. Maybe this function is undocumented but usable.

kannand
Lapis Lazuli | Level 10

It is possible that the reserved word functionality is for its internal use and if a user wants to use the name could use it through double quotes as per the documentation. 

Kannan Deivasigamani
Haikuo
Onyx | Level 15

I would still consider FeqSQL as an very early implementation (new to 9.4) of ANSI SQL:1999 core standard, which is the part of 'in-database' prcessing effort along with DS2. Let's hope those reserved key words maybe put in use in the future release. As for the time being, you can still leverage ODS for the same functionality:

 

ods listing close;
ods output fedsql_results=want;
proc fedsql number;
select * from yourlib.have
;
quit;
ods listing;
jflycn
Calcite | Level 5

Haikuo, thanks for your response. My interpretation is the same as yours, i.e. ROW_NUMBER is a reserved word in FedSQL only means a possibility of future implementation.

 

Also thanks for your suggestion, but I guess this ODS approach won't work for ROW_NUMBER by group. I do know other turn around approaches to get ROW_NUMBER by group, just hope there is a staightfoward way of doing this in SAS.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2518 views
  • 0 likes
  • 3 in conversation