BookmarkSubscribeRSS Feed
Lucasmarques94
Calcite | Level 5

Preciso fazer a subtração de duas colunas de data e hora, tentei o INTCK mas não funcionou!

 

Em teoria o meu projeto que estou desenvolvendo é verificar se em um período de 96 horas eu tive a criação de notas de serviço para uma mesma instalação. 

 

Se alguém puder me ajudar ficarei extremamente grato.

1 REPLY 1
SASJedi
SAS Super FREQ

Se apenas precisas listar rows que contenham um valor de data/hora dentro de 96 horas de uma data especificada, pode usar PROC SQL e a cláusula BETWEEN. Veja:

/* Aqui só estou criando ums dados falsos */
data meus_dados;
	call streaminit(12345);
	length Instalacao DataDoNoticia 8 Nota $10;
	DataDoNoticia='15APR2024:00:00:00'dt;
	format DataDoNoticia E8601DT18.;
	array palavra [5] $10 _temporary_ ('Ótimo','Bom','Mal','Locura','Péssimo');
	DO Instalacao =1 to 10;
		do I= 1 to rand('integer',2,5);
			DataDoNoticia+(86400*I);
			Nota=palavra[rand('integer',1,5)];
			output;
		end;
	end;
	drop i;
run;
title 'Exemplo dos Meus Dados';
proc print data=meus_dados(obs=5);
run;
Exemplo dos Meus Dados

Obs Instalacao DataDoNoticia Nota
1 1 2024-04-16T0:00:00 Péssimo
2 1 2024-04-18T0:00:00 Mal
3 1 2024-04-21T0:00:00 Péssimo
4 1 2024-04-25T0:00:00 Péssimo
5 2 2024-04-26T0:00:00 Locura

 

 

/* Aqui começa o trabalho */
%let comeco="25APR2024:00:00:00"dt;
%let fim=&comeco+345600;

%put %superq(comeco) %superq(fim);

title "Instalações com noticias dentro de 96 horas desde %qscan(%superq(comeco),1,%str(%"))";

proc sql;
select Instalacao
		,min(DataDoNoticia) format=E8601DT18. as PrimeiraData
		,count(*) as Conta
	from meus_dados
	where DataDoNoticia between &comeco and &fim
	group by Instalacao
;
quit;
Instalações com noticias dentro de 96 horas desde 25APR2024:00:00:00

Instalacao PrimeiraData Conta
1 2024-04-25T0:00:00 1
2 2024-04-26T0:00:00 2

 

Check out my Jedi SAS Tricks for SAS Users

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!

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
  • 1 reply
  • 139 views
  • 0 likes
  • 2 in conversation