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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 2480 views
  • 2 likes
  • 3 in conversation