Boa tarde!
Prezados, alguém consegue ajudar na query abaixo:
A ideia e´ trazer apenas os registros dos últimos 30 dias, conforme o campo
"WHERE DATEPART(NM_DATA_ANALISE) >= (DATE()- 30);"
Contudo, o resultado esta trazendo todo o período, como se não tivesse o filtro de data.
PROC SQL;
CREATE TABLE WORK.ANALISE_01 AS
SELECT
NR_SINISTRO,
NM_BANCO,
NM_PROCURADOR,
NM_AGENCIA,
NM_STATUS,
NM_DATA_ANALISE
FROM PESSOAL.NM_ANALISE;
WHERE DATEPART(NM_DATA_ANALISE) >= (DATE()- 30);
QUIT;
Place the closing semicolon of a multiple line statement on its own line to avoid such confusion.
Google Translate:
Coloque o ponto e vírgula de fechamento de uma instrução de múltiplas linhas em sua própria linha para evitar tal confusão.
CREATE TABLE WORK.ANALISE_01 AS
SELECT
NR_SINISTRO
, NM_BANCO
, NM_PROCURADOR
, NM_AGENCIA
, NM_STATUS
, NM_DATA_ANALISE
FROM PESSOAL.NM_ANALISE
WHERE DATEPART(NM_DATA_ANALISE) >= (DATE()- 30)
;
Boa tarde!
Realmente tinha uma " ; " na frente do FROM de forma errada, descuido meu.
De qualquer forma, após a correção do script, rodou corretamente, porém não trouxe informações, o output veio vazio.
Cheguei a substituir o DATE por TODAY, porém não houve mudança.
Alguma ideia de como resolver essa questão?
PROC SQL;
CREATE TABLE WORK.ANALISE_01 AS
SELECT
NR_SINISTRO,
NM_BANCO,
NM_PROCURADOR,
NM_AGENCIA,
NM_STATUS,
NM_DATA_ANALISE
FROM PESSOAL.NM_ANALISE
WHERE
DATEPART(NM_DATA_ANALISE) >= (DATE() - 60);
QUIT;
If there is no output, then a possible solution is to remove the DATEPART function, as it might not be needed here.
Se não houver saída, uma solução possível é remover a função DATEPART, pois ela pode não ser necessária aqui.
Are you sure that nm_data_analise is a datetime and not a date? Please run PROC CONTENTS and post the resulting output for that variable.
Boa tarde!
Não é isso também.
A tabela esta´ correta e possui intervalo de datas dentro do filtro estipulado.
Cheguei a testar com 30, 60, 90, 120 dias para traz, porem não deu certo.
Eu imagino que seja alguma coisa referente ao tipo do campo, contudo, o mesmo esta tambem já no formato de data.
Tabela => FROM PESSOAL.NM_ANALISE
@LUISFELIPE10 wrote:
Boa tarde!
Não é isso também.
A tabela esta´ correta e possui intervalo de datas dentro do filtro estipulado.
Cheguei a testar com 30, 60, 90, 120 dias para traz, porem não deu certo.
Eu imagino que seja alguma coisa referente ao tipo do campo, contudo, o mesmo esta tambem já no formato de data.
Tabela => FROM PESSOAL.NM_ANALISE
I don't see any reason you need DATEPART, which will likely give the wrong answer. Did you try it without DATEPART?
By the way I agree with @Kurt_Bremser , show us the PROC CONTENTS output for this variable.
Boa tarde!
É exatamente isso, não havia necessidade de utilizar o DATEPART.
Não havia testado sem ele anteriormente.
Tirei ele da query e testei novamente e o resultado apareceu corretamente.
Muito obrigado pela ajuda.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.