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

Hi,

 

I do not understand why SAS has a result different for same dates. Only format is different, date or datetime.

 

Why happen this? I need the format datetime21.3

 

%let tdate = %sysfunc(today(),date9.);
%put &tdate.;

 %let dois_anos_fmt = %sysfunc(intnx(year, %sysfunc(today()), -2, same), date9.);
 %put &dois_anos_fmt.;

result: 

 

36 GOPTIONS ACCESSIBLE;
37 %let tdate = %sysfunc(today(),date9.);
38 %put &tdate.;
07MAY2018
39
40 %let dois_anos_fmt = %sysfunc(intnx(year, %sysfunc(today()), -2, same), date9.);
41 %put &dois_anos_fmt.;
07MAY2016

 

%let data_requerida = %sysfunc(today(),datetime21.3);
%put &data_requerida.;

 %let data_dois_anos_menos = %sysfunc(intnx(year, %sysfunc(today()), -2, same), datetime21.3);
 %put &data_dois_anos_menos.;

result:

 

55 %let data_requerida = %sysfunc(today(),datetime21.3);
56 %put &data_requerida.;
01JAN60:05:55:11.000
57
58 %let data_dois_anos_menos = %sysfunc(intnx(year, %sysfunc(today()), -2, same), datetime21.3);
59 %put &data_dois_anos_menos.;
01JAN60:05:43:01.000

 

 

Regards,

Aleixo

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Try this corrected code of your second version

 %let data_requerida = %sysfunc(datetime(), datetime21.3);
 %put &data_requerida.;


%let data_dois_anos_menos = %sysfunc(intnx(dtyear, %sysfunc(datetime()), -2, same), datetime21.3);
 %put &data_dois_anos_menos.;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

your code

 

%let data_requerida = %sysfunc(today(),datetime21.3);
%put &data_requerida.;

Today() returns a date value and not a datetime value that you are trying to format using a datetime format

Astounding
PROC Star

Dates and times are different.  You can't substitute one for the other.  It just doesn't work.  It's like saying, "I baked a cake and I used ketchup instead of sugar.  But it didn't come out right.  Why?"  They're just plain different.

 

To understand what SAS is expecting, you can start here:

 

https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002200738.htm

 

 

novinosrin
Tourmaline | Level 20

Try this corrected code of your second version

 %let data_requerida = %sysfunc(datetime(), datetime21.3);
 %put &data_requerida.;


%let data_dois_anos_menos = %sysfunc(intnx(dtyear, %sysfunc(datetime()), -2, same), datetime21.3);
 %put &data_dois_anos_menos.;
Aleixo
Quartz | Level 8

Thank you all. 

 

Yes the right function is datetime()

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
  • 833 views
  • 0 likes
  • 3 in conversation