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

Estou com esse programa para colocar no SAS, porem qdo tento passar para o SAS dá um monte de ERROS. 

Alguém pode me ajudar.

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Aqui está um dos seus códigos MERGE INTO que eu converti Da mesma forma primeiro crie uma tabela e, em seguida, use o método HASH TABLE para atualizar a tabela com eficiência.

 

 

MERGE INTO RELAT_PARCELAS_PENDENTES2 R 
USING (
    ** (OBTER O CD_RAMO DA COBERTURA BÁSICA DO PRODUTO)
    SELECT DISTINCT 
          RM_COB_BAS.CD_RAMO,
          RM_COB_BAS.NO_RAMO,
          RM_COB_BAS.NM_RAMO,
          RM_PROD.NO_GRUPO_RAMO,
          PR.CD_PRODUTO
        FROM vnova.smv_PLANO_ITEM PI
          JOIN vnova.smv_PLANO PL ON PI.CD_PLANO = PL.CD_PLANO
          JOIN vnova.smv_PRODUTO PR ON PR.CD_PRODUTO = PL.CD_PRODUTO
          JOIN vnova.smv_EMPRESA E ON E.CD_EMPRESA = PR.CD_EMPRESA
          JOIN vnova.smv_RAMO RM_COB_BAS ON PI.CD_RAMO = RM_COB_BAS.CD_RAMO
          JOIN vnova.smv_RAMO RM_PROD ON PR.CD_RAMO = RM_PROD.CD_RAMO
        WHERE 
          CD_TIPO_PLANO_ITEM = 'BAS' 
          AND E.CD_CIA_SUSEP = 40
    ) 
    S ON (
        S.CD_PRODUTO = R.CD_PRODUTO
    )
WHEN MATCHED THEN
    UPDATE SET 
        R.CD_RAMO = S.CD_RAMO,
        R.NO_RAMO = S.NO_RAMO,
        R.NM_RAMO = S.NM_RAMO,
        R.NO_GRUPO_RAMO = S.NO_GRUPO_RAMO
    ;
/*  Converteu o MERGE INTO acima */
PROC SQL;
CREATE TABLE STAGE_UPDATE1 AS 
    SELECT DISTINCT 
          RM_COB_BAS.CD_RAMO,
          RM_COB_BAS.NO_RAMO,
          RM_COB_BAS.NM_RAMO,
          RM_PROD.NO_GRUPO_RAMO,
          PR.CD_PRODUTO
        FROM vnova.smv_PLANO_ITEM PI
          JOIN vnova.smv_PLANO PL ON PI.CD_PLANO = PL.CD_PLANO
          JOIN vnova.smv_PRODUTO PR ON PR.CD_PRODUTO = PL.CD_PRODUTO
          JOIN vnova.smv_EMPRESA E ON E.CD_EMPRESA = PR.CD_EMPRESA
          JOIN vnova.smv_RAMO RM_COB_BAS ON PI.CD_RAMO = RM_COB_BAS.CD_RAMO
          JOIN vnova.smv_RAMO RM_PROD ON PR.CD_RAMO = RM_PROD.CD_RAMO
        WHERE 
          CD_TIPO_PLANO_ITEM = 'BAS' 
          AND E.CD_CIA_SUSEP = 40
	;
QUIT;

data RELAT_PARCELAS_PENDENTES2;  
  if _n_=1 then do;
    declare hash ud(dataset:'STAGE_UPDATE1');
    ud.defineKey('CD_PRODUTO');
    ud.defineData('CD_RAMO', 'NO_RAMO', 'NM_RAMO', 'NO_GRUPO_RAMO');
    ud.defineDone();
  end;
  modify RELAT_PARCELAS_PENDENTES2;
  rcUpdate = ud.find();
  if rcUpdate=0 then replace;
run;

 

Thanks,
Suryakiran

View solution in original post

11 REPLIES 11
tomrvincent
Rhodochrosite | Level 12

 

Dê um passo de cada vez.

Você não precisa criar a tabela. Faça um 'create table RELAT_PARCELAS_PENDENTES2 as' no passo 1.

Além disso, não há uma 'mesclagem' no SAS SQL, então você terá que fazer isso em 2 etapas.

diogoalmas
Calcite | Level 5

Esta dando ERRO na parte do MERGE INTO.

tomrvincent
Rhodochrosite | Level 12

 

Selecione os registros correspondentes diretamente e, em seguida, você pode fazer uma atualização de RELAT_PARCELAS_PENDENTES2.
SuryaKiran
Meteorite | Level 14

MERGE INTO não é a sintaxe do SAS. Tente passar o código para o banco de dados em vez de converter para o SAS SQL.

 

proc sql;
connect to oracle (user=testuser password=testpass);
execute ( seu código oracle )
by oracle;

quit;

 

trazer a tabela temporária para o SAS

 

proc sql;
connect to oracle (user=testuser password=testpass);
CREATE TABLE RELAT_PARCELAS_PENDENTES2 as
select *
from connection to oracle
(select * from RELAT_PARCELAS_PENDENTES2);
disconnect from oracle;

quit;

 

desde a sua criação de tabela temporária não se esqueça de mencionar ON COMMIT PRESERVE ROWS

Thanks,
Suryakiran
diogoalmas
Calcite | Level 5

o problema é que na minha empresa eu não tenho senha para acessar o Oracle, as tabelas estão espelhadas no ambiente SAS.

SuryaKiran
Meteorite | Level 14

O que você quer dizer com espelhado? Verifique se os LIBANMES foram atribuídos usando o ID de grupo AUTHDOMAIN =. Você pode usar este Authdomain = para acessar diretamente as tabelas por meio de pass-through.

proc sql;
   connect to oracle (Authdomain=);
   execute (create view whotookorders as
      select ordernum, takenby,  
             firstname, lastname, phone
         from orders, employees
         where orders.takenby=employees.empid)
      by oracle;
   execute (grant select on whotookorders 
            to testuser) by oracle;
   disconnect from oracle;
quit;

Desculpe se meu texto não faz sentido. eu estou usando o Google Tradutor

Thanks,
Suryakiran
SuryaKiran
Meteorite | Level 14

Aqui está um dos seus códigos MERGE INTO que eu converti Da mesma forma primeiro crie uma tabela e, em seguida, use o método HASH TABLE para atualizar a tabela com eficiência.

 

 

MERGE INTO RELAT_PARCELAS_PENDENTES2 R 
USING (
    ** (OBTER O CD_RAMO DA COBERTURA BÁSICA DO PRODUTO)
    SELECT DISTINCT 
          RM_COB_BAS.CD_RAMO,
          RM_COB_BAS.NO_RAMO,
          RM_COB_BAS.NM_RAMO,
          RM_PROD.NO_GRUPO_RAMO,
          PR.CD_PRODUTO
        FROM vnova.smv_PLANO_ITEM PI
          JOIN vnova.smv_PLANO PL ON PI.CD_PLANO = PL.CD_PLANO
          JOIN vnova.smv_PRODUTO PR ON PR.CD_PRODUTO = PL.CD_PRODUTO
          JOIN vnova.smv_EMPRESA E ON E.CD_EMPRESA = PR.CD_EMPRESA
          JOIN vnova.smv_RAMO RM_COB_BAS ON PI.CD_RAMO = RM_COB_BAS.CD_RAMO
          JOIN vnova.smv_RAMO RM_PROD ON PR.CD_RAMO = RM_PROD.CD_RAMO
        WHERE 
          CD_TIPO_PLANO_ITEM = 'BAS' 
          AND E.CD_CIA_SUSEP = 40
    ) 
    S ON (
        S.CD_PRODUTO = R.CD_PRODUTO
    )
WHEN MATCHED THEN
    UPDATE SET 
        R.CD_RAMO = S.CD_RAMO,
        R.NO_RAMO = S.NO_RAMO,
        R.NM_RAMO = S.NM_RAMO,
        R.NO_GRUPO_RAMO = S.NO_GRUPO_RAMO
    ;
/*  Converteu o MERGE INTO acima */
PROC SQL;
CREATE TABLE STAGE_UPDATE1 AS 
    SELECT DISTINCT 
          RM_COB_BAS.CD_RAMO,
          RM_COB_BAS.NO_RAMO,
          RM_COB_BAS.NM_RAMO,
          RM_PROD.NO_GRUPO_RAMO,
          PR.CD_PRODUTO
        FROM vnova.smv_PLANO_ITEM PI
          JOIN vnova.smv_PLANO PL ON PI.CD_PLANO = PL.CD_PLANO
          JOIN vnova.smv_PRODUTO PR ON PR.CD_PRODUTO = PL.CD_PRODUTO
          JOIN vnova.smv_EMPRESA E ON E.CD_EMPRESA = PR.CD_EMPRESA
          JOIN vnova.smv_RAMO RM_COB_BAS ON PI.CD_RAMO = RM_COB_BAS.CD_RAMO
          JOIN vnova.smv_RAMO RM_PROD ON PR.CD_RAMO = RM_PROD.CD_RAMO
        WHERE 
          CD_TIPO_PLANO_ITEM = 'BAS' 
          AND E.CD_CIA_SUSEP = 40
	;
QUIT;

data RELAT_PARCELAS_PENDENTES2;  
  if _n_=1 then do;
    declare hash ud(dataset:'STAGE_UPDATE1');
    ud.defineKey('CD_PRODUTO');
    ud.defineData('CD_RAMO', 'NO_RAMO', 'NM_RAMO', 'NO_GRUPO_RAMO');
    ud.defineDone();
  end;
  modify RELAT_PARCELAS_PENDENTES2;
  rcUpdate = ud.find();
  if rcUpdate=0 then replace;
run;

 

Thanks,
Suryakiran
diogoalmas
Calcite | Level 5
Prezado,

Alterei o programa conforme sugestão.

Só que agora está dando esse ERRO.

Você sabe o que pode ser?

ERROR: Hash object added 1441776 items when memory failure occurred.

FATAL: Insufficient memory to execute DATA step program. Aborted during the
EXECUTION phase.

ERROR: The SAS System stopped processing this step because of insufficient
memory.

Essa falta de memoria é no servidor ou na minha máquina?

SuryaKiran
Meteorite | Level 14

Tabelas de hash são armazenadas na memória. Você está tentando armazenar um volume muito grande de dados na memória que não é permitido. Tente dividir seus dados e tente carregar. Por exemplo, table1 precisa ser atualizado por table2, que é 1 milhão de registros, dividir esta tabela2 em 4 tabelas a cada 250000 e, em seguida, carregar cada uma individualmente.

 

Thanks,
Suryakiran
diogoalmas
Calcite | Level 5

Prezado,

Alterei o programa conforme sugestão.

Só que agora está dando esse ERRO.

Você sabe o que pode ser?

ERROR: Hash object added 1441776 items when memory failure occurred.

FATAL: Insufficient memory to execute DATA step program. Aborted during the
EXECUTION phase.

ERROR: The SAS System stopped processing this step because of insufficient
memory.

Essa falta de memoria é no servidor ou na minha máquina?

SuryaKiran
Meteorite | Level 14

Looks like you have PL/SQL that your trying to convert into SAS SQL. Do you know you can run the native SQL directly by passing it to database (explicit pass-through). 

For example: 

 

proc sql;
   connect to oracle (user=testuser password=testpass);
   execute (create view whotookorders as
      select ordernum, takenby,  
             firstname, lastname, phone
         from orders, employees
         where orders.takenby=employees.empid)
      by oracle;
   execute (grant select on whotookorders 
            to testuser) by oracle;
   disconnect from oracle;
quit;

 

 

 

Thanks,
Suryakiran

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 11 replies
  • 2517 views
  • 1 like
  • 3 in conversation