How to filter importing data in a specific time range?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 109
Accepted Solution

How to filter importing data in a specific time range?

Hello everybody.

I have variables which its attributs are showed below:

 

Alphabetic List of Variables and Attributes
# Variable      Type      Len       Format       Informat            Label
TRD_EVENT_DTNum8DATE9.DATE9.TRD_EVENT_DT
TRD_EVENT_MSChar1$1.$1.TRD_EVENT_MS
TRD_EVENT_TMChar8$8.$8.TRD_EVENT_TM
TRD_INSTR_NAMEChar9$9.$9.TRD_INSTR_NAME
TRD_PRChar5$5.$5.TRD_PR
TRD_STCK_CDChar5$5.$5.TRD_STCK_CD
TRD_STCK_GRP_ID_CDChar2$2.$2.TRD_STCK_GRP_ID_CD
TRD_STCK_IDChar12$12.$12.TRD_STCK_ID
TRD_TRA_NRChar10$10.$10.TRD_TRA_NR
TRD_TUROVRChar9$9.$9.TRD_TUROVR

 

Explanation of variables of some columns:

[TRD_EVENT_DT] Month / Day / Year
,[TRD_EVENT_TM] Time: hh:mm:ss
,[TRD_PR] Stock Price
,[TRD_TUROVR] Turnover.

 

I want to create filter on the data source in a specific time range. The time variable is between 9:00 till ~16:00. However, I just want to limit data set between 9:00 till 12:00.

How can I do that?

Thanks in advance.


Accepted Solutions
Solution
‎06-13-2017 04:14 PM
PROC Star
Posts: 7,363

Re: How to filter importing data in a specific time range?

Since your time variable is shown as char8, I'd try:

 

data want;
  set have;
  if '09:00't le input(TRD_EVENT_TM,time8.) le '12:00't;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎06-13-2017 04:14 PM
PROC Star
Posts: 7,363

Re: How to filter importing data in a specific time range?

Since your time variable is shown as char8, I'd try:

 

data want;
  set have;
  if '09:00't le input(TRD_EVENT_TM,time8.) le '12:00't;
run;

Art, CEO, AnalystFinder.com

 

Super User
Posts: 17,840

Re: How to filter importing data in a specific time range?

Why haven't you changed the type/format to a date/datetime rather than character?

A lot of your questions could be answered very simply if you specified them as time/date/datetime variables. 

 

where hour(time_variable) between 9 and 12;

 

http://support.sas.com/resources/papers/proceedings10/134-2010.pdf

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 127 views
  • 2 likes
  • 3 in conversation