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

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!
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
  • 258 views
  • 0 likes
  • 2 in conversation