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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1788 views
  • 0 likes
  • 3 in conversation