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

Hey Guys,

 

in my next job I have to work with SAS Visual Analytics because of this I have created a Trial Account on SAS Viya. At the SAS Data Studio in Transformation Code (CASL Editor), I have a problem with a subquery. I have created the following query in FedSQL.

 

loadActionSet 'fedsql';
queryCode = 'create table "'||_dp_outputCaslib||'"."'||_dp_outputTable||'" {options replace=true}
as select ID, Stadt, Stadt_upper, Einwohner, Bundesland, 
(Select sum(Einwohner) from "'||_dp_inputCaslib||'"."'||_dp_inputTable||'" as b where b.Bundesland = a.Bundesland) as Sum_Bundesland
from "'||_dp_inputCaslib||'"."'||_dp_inputTable||'" as a'; 
print queryCode;
ExecDirect / query=queryCode;

And i receive the following error message...

The action was not successful
ERROR: Unsupported operation in FedSQL query: Correlated subquery.

 

After this message I change from FedSQL to PROC SQL.

 

loadActionSet 'proc sql';
queryCode = 'create table "'||_dp_outputCaslib||'"."'||_dp_outputTable||'" {options replace=true}
as select ID, Stadt, Stadt_upper, Einwohner, Bundesland, 
(Select sum(Einwohner) from "'||_dp_inputCaslib||'"."'||_dp_inputTable||'" as b where b.Bundesland = a.Bundesland) as Sum_Bundesland
from "'||_dp_inputCaslib||'"."'||_dp_inputTable||'" as a'; 
print queryCode;
ExecDirect / query=queryCode;

This is the next error message...

The action was not successful
ERROR: Load access denied for user xxx.xxx@xxx.de on action set _UNREGISTERED.
ERROR: Action set 'proc sql' was not loaded due to errors.

 

What do I have to do, to use subquerys in the transformation code Step in SAS Data Studio?

 

Regards and thank you...

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Only FedSQL has been implemented in CAS. The FedSQL SQL implementation only supports non-correlated queries as documented here

 

From a coding perspective: Depending on the Viya version there are many things for which you don't need action sets but can use more "traditional" SAS syntax. For what you're doing the following two coding approaches should work (not tested).

proc fedsql sessref=mysess;
  create table _dp_outputCaslib._dp_outputTable {options replace=true} as
  select 
    id, 
    stadt, 
    stadt_upper, 
    einwohner, 
    bundesland,
    sum(Einwohner) as Sum_Bundesland
    from _dp_inputCaslib._dp_inputTable
    group by 
    id, 
    stadt, 
    stadt_upper, 
    einwohner, 
    bundesland    
  ;

 

 

data _dp_outputCaslib._dp_outputTable;
  set _dp_inputCaslib._dp_inputTable;
  by Bundesland;
  keep id stadt stadt_upper einwohner bundesland sum_bundesland;
  retain sum_bundesland;
  if first.bundesland then sum_bumdesland=0;
  sum_bumdesland=sum(sum_bumdesland,Einwohner);
run;

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

Only FedSQL has been implemented in CAS. The FedSQL SQL implementation only supports non-correlated queries as documented here

 

From a coding perspective: Depending on the Viya version there are many things for which you don't need action sets but can use more "traditional" SAS syntax. For what you're doing the following two coding approaches should work (not tested).

proc fedsql sessref=mysess;
  create table _dp_outputCaslib._dp_outputTable {options replace=true} as
  select 
    id, 
    stadt, 
    stadt_upper, 
    einwohner, 
    bundesland,
    sum(Einwohner) as Sum_Bundesland
    from _dp_inputCaslib._dp_inputTable
    group by 
    id, 
    stadt, 
    stadt_upper, 
    einwohner, 
    bundesland    
  ;

 

 

data _dp_outputCaslib._dp_outputTable;
  set _dp_inputCaslib._dp_inputTable;
  by Bundesland;
  keep id stadt stadt_upper einwohner bundesland sum_bundesland;
  retain sum_bundesland;
  if first.bundesland then sum_bumdesland=0;
  sum_bumdesland=sum(sum_bumdesland,Einwohner);
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 1495 views
  • 0 likes
  • 2 in conversation