BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NN
Quartz | Level 8 NN
Quartz | Level 8

Hi,

If your objective is to provide a date & time range  or value

Then as a sample you can try using the below code in your code section

%macro report();

proc sql;

select count(*) from

sashelp.timedata where datetime

/*if using mulitple values  then uncomment the below code*/

/* in (*/

/*%if &date_count  = 1 %then %do;*/

/*"&date"dt*/

/*%end;*/

/*%else %do i=1 %to &date_count;*/

/*"&&date&i"dt*/
/*%end;*/

/*);*/

/*if using using a  range then uncomment the below code*/

/*between "&date_min"dt and "&date_max"dt  ;*/

run;


%mend;

%report;

Donot forget to  use timestamp or Timestamp range as your prompt type... Same should then work..

Your Prompt Values would look something like  January 12, 1998 06:00:00 AM

seven_snow
Calcite | Level 5

Thanks all - for your valuable inputs! My issue is resolved now.

Whether few things worked or not, I have still learnt from your comments.

Smiley Happy

Peter_C
Rhodochrosite | Level 12

a suggestion,  I hope you'll find useful

When filtering a datetime value, don;t convert it to compare against date constants!

Just convert the constants, like:

where datetime_value between "&date1:0:0"dt and "&date2:23:59:59.999"dt

seven_snow
Calcite | Level 5

Peter, thanks for your suggestion, but I am afraid to confess that I did not understand your point. Please elaborate a little.

My Understanding:

"datetime_value" is a value selected from the calender that the prompts give in.

"&date1:0:0"dt" is the actual value from the table.

For example,

After executing the STP, when I select the value from the prompts' calender option, it displays: "October 01, 2010 11:09:19 AM"--(1)

Value from actual table is displayed as: "01OCT2010:00:00:00"--(2)

And you want to convey that we should not filter like: datepart(2) = datepart(1) ?

Also, I did not understand how to convert the constants? -> "&date2:23:59:59.999"dt ??

Peter_C
Rhodochrosite | Level 12

pardon me if I'm only adding confusion.

I imagined you were comparing  data values stored as standard SAS datetime values. There is a datetime constant syntax. Some posters suggest extracting the datepart before comparing a datetime value with a constant date.

From your reply I presume your objective is to compare values as text, so my suggestion is inappropriate.

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!

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
  • 19 replies
  • 5124 views
  • 8 likes
  • 5 in conversation