BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
_el_doredo
Quartz | Level 8

Hello Experts,
I am having a table which has more than 10billion records. By using PROC SQL, it prints the count in exponential value.
Due to that, I am using PROC FEDSQL to print the values. However, I want to print table name as well in my output. But, PROC FEDSQL considering hardcoded value as a column and searching it against the table and erroring by saying “Column not found”. Please help me to resolve this error.

I have added the code below

%LET TABLE_NAME=Sales;
PROC FEDSQL;
CREATE TABLE WANT AS
SELECT “&TABLE_NAME.” as Table_Name,
CAST(COUNT(*) AS BIGINT) as Count
From Sales;
QUIT;

I am fetching count for many tables so I can’t hardcode table name directly. If I hardcode directly it’s working fine. But while resolving the hardcoded value in macro variable it’s considering it as a variable

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
%let table_name = SALES; /* use uppercase! */

proc sql;
create table want as
  select
    memname as table_name,
    nobs as count format=15. /* increase format if needed */
  from dictionary.tables
  where libname = "WORK" and memname = "&table_name."
;
quit;

Query the metadata instead of reading the whole dataset.

 

PS to do this for several datasets, create a dataset with libnames and memnames (all uppercase) and do a join with DICTIONARY.TABLES.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User
%let table_name = SALES; /* use uppercase! */

proc sql;
create table want as
  select
    memname as table_name,
    nobs as count format=15. /* increase format if needed */
  from dictionary.tables
  where libname = "WORK" and memname = "&table_name."
;
quit;

Query the metadata instead of reading the whole dataset.

 

PS to do this for several datasets, create a dataset with libnames and memnames (all uppercase) and do a join with DICTIONARY.TABLES.

Tom
Super User Tom
Super User

I suspect that PROC FEDSQL is treating "XXX" as a NAME instead of STRING LITERAL.  Just like PROC SQL would if you use the DQUOTE=ANSI option.

 

Try using single quotes.

%let TABLE_NAME=Sales;
proc fedsql;
create table WANT as
  select %unquote(%bquote('&TABLE_NAME')) as Table_Name
       , CAST(COUNT(*) AS BIGINT) as Count
  from &table_name
;
quit;

Note that trying to store an actual BIGINT value into a SAS numeric variable might cause trouble.  The maximum integer that SAS can store exactly is 9,007,199,254,740,992.

1    data _null_;
2      maxint=constant('exactint');
3      put maxint= comma32.;
4    run;

maxint=9,007,199,254,740,992
AhmedAl_Attar
Ammonite | Level 13

@_el_doredo 

To use macro variable in Proc FedSQL, you'll need to use the SAS macro function %TSLIT.

Check this on-line doc for reference SAS Help Center: Macro Variables

_el_doredo
Quartz | Level 8

Hi all,

Thanks for your response. All responses are working fine and another response I found is mentioning table name in single quotes also resolving this issue.

 

%LET TABLE_NAME=‘Sales’;
PROC FEDSQL;
CREATE TABLE WANT AS
SELECT “&TABLE_NAME.” as Table_Name,
CAST(COUNT(*) AS BIGINT) as Count
From Sales;
QUIT;

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 639 views
  • 4 likes
  • 4 in conversation