BookmarkSubscribeRSS Feed
yiapipi
Calcite | Level 5

hi All, i'm in truble subtracting "date" (from %Let) with another "date" field....

following is showed the code definition...

%let rundt = %sysfunc(date(),date9.)

---

---

select

663 NDG_OPERATORE_ECONOMICO,

664 COD_TIPO_ORG,

665 COD_FORMA_GIURIDICA,

666 DTA_NAS,

667 rundt. - DTA_NAS as delta_date,

                 -

                22

668 case when rundt. - DTA_NAS >= 540 then 'NO_Start_UP'

                                    -

                                   22

ERROR 22-322: Syntax error, expecting one of the following: un nome, *.

669 else 'SI_Start_UP'

670 end AS Start_UP

671

672

673 FROM ANGRFC.ANA_OPERATORE_ECONOMICO

674 GROUP BY 1,2,3,4,5

-

 

 

thank's in advance for your support and suggestions

Pio Piccinin

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You need to look at what Base SAS code is generated from the find/replace macro system.  There are also some issues with your code (which you have not supplied).  So you create a text macro variable with the string 13DEC2018, this then goes into your actual code ti form the line:

13DEC2018 - DTA_NAS as delta_date,

As you can clearly see that is not valid Base SAS code.  To rectify this you would put the string between quotes, and put a d after it to use SAS implicit date conversion, something like:

"&rundt."d - DTA_NAS as delta_date,

Also, you are missing a semicolon after the end of the %let.  And do avoid coding all in shouting case, it makes reading the code so much harder!

 

Kurt_Bremser
Super User
  1. Macro variables need to be adressed with a leading ampersand: &rundt.
  2. A date value formatted with date9. will result in a string that cannot be used as a number (13DEC2018 is not a numeric literal); see Maxim 28.

Try this code for reference:

%let rundt=%sysfunc(today());

data test;
value = today() -5;
result = &rundt. - value;
format value yymmddd10.;
run;

proc print data=test noobs;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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