DATA Step, Macro, Functions and more

DATETIME20 Results based on last 12 hours of data

Reply
Occasional Contributor
Posts: 13

DATETIME20 Results based on last 12 hours of data

Good Afternoon,

 

I have a question that's stumping me, more than likely a very simple answer, however I haven't been able to come up with a working solution as of yet. 

 

I create a SAS7BDAT file that SAS writes data to, for each program we run (Logging start time, date, filename, End time and a list of activities (0000 for example would mean the program initiated, 9999 Means it ended). The format it write in is delimited with a ",".

 

My issue is when I'm reading in the file (No issues up to, and just after reading in the SAS7BDAT). I'm trying to hold information in a dataset of ONLY the programs that have run in the last 12 hours. 

 

*IMPORTANT*

The Date format being read in is in DATETIME20. Format (Which needs to remain the same).

 

Any help would be greatly appreciated!

 

What has been suggested, though not sure how to work a variable in instead of datalines.

 

format seconds minutes hours days weeks datetime20.;
format t_seconds t_minutes t_hours time9.;

hours=intnx('hour', '&DATE_FROM'dt, -12);

Super User
Posts: 6,928

Re: DATETIME20 Results based on last 12 hours of data

Macro variables are not resolved inside single quotes; use double quotes instead.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Trusted Advisor
Posts: 1,353

Re: DATETIME20 Results based on last 12 hours of data

If you want exactly 12 hourse add an option to the INTNX function:

 

start_time = intnx('hour', '&DATE_FROM'dt, -12,same);

 

The option "same" means same at seconds accuracy  as end_time.

Occasional Contributor
Posts: 13

Re: DATETIME20 Results based on last 12 hours of data

Hi, 

So of course, the second I finished sending this, I figured it out. 

Though, I would still like to see what others come up with. But if anyone is wondering how I did it (Though I wont include my main code, I will show my solution).

 

%LET SE = %SYSFUNC(PUTN(%SYSEVALF(%SYSFUNC(DATETIME())),DATETIME20.3));

DAta temp.DEF;
SE = "&SE." ;
format seconds minutes hours days weeks datetime20.;
hours=intnx('hour', "' &SE. '"dt, -12);

RUN;

Occasional Contributor
Posts: 13

Re: DATETIME20 Results based on last 12 hours of data

Thanks Shmuel,

 

I like the same part! Also it's actually not single quotes, or double. Thats where I was going wrong. It's wrapped in Double then single quotes.

 

Monster

Ask a Question
Discussion stats
  • 4 replies
  • 122 views
  • 0 likes
  • 3 in conversation