BookmarkSubscribeRSS Feed
XMonsterX
Obsidian | Level 7

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);

4 REPLIES 4
Shmuel
Garnet | Level 18

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.

XMonsterX
Obsidian | Level 7

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;

XMonsterX
Obsidian | Level 7

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

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 762 views
  • 0 likes
  • 3 in conversation