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

Hi All,

 

Appreciate your advice what function or formula should i input if i would like to get a yesterday date in EG to show in the Table Title 

 

In excel formula is  (Today()-1), how about in SAS ? i have tried this %sysfunc(today()-1, ddmmyy10) but it doesn't work

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@SASnewbie2 wrote:

SAS.png

Hi Partick,

 

Can i copy & past into the table titles as shown above ? I

 

try to run it, but it doesn't seem work. Am i miss out something ? 


 

Remove the %PUT statement. Below the bit which you need to pass in for your title

%sysfunc(sum(%sysfunc(today()),-1), nldate20. -l)

View solution in original post

12 REPLIES 12
Kurt_Bremser
Super User

It's the same, literally:

data _null_;
format date yymmddd10.;
date = today();
put date=;
date = today() - 1;
put date=;
run;

Log:

27         data _null_;
28         format date yymmddd10.;
29         date = today();
30         put date=;
31         date = today() - 1;
32         put date=;
33         run;

date=2018-05-25
date=2018-05-24
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
SASnewbie2
Fluorite | Level 6

Hi Kurtbremser, 

 

Thanks for your advice. However, I would like to have the yesterday date in the Table title. 

 

Appreciate you could advise how should i revise the formula below .

 

Sales Revenue as at %TRIM(%QSYSFUNC(DATE(), NLDATE20.)) to become Sales Revenue as at 24.05.2018 (One day before)

 

 

Kurt_Bremser
Super User

When I need to more that a simple assignment, I use to create macro variables in a data step for easier readable code:

data _null_;
call symput('yesterday',trim(put(today()-1,nldate20.)));
run;

title "SASHELP.CLASS at &yesterday";

proc print data=sashelp.class;
run;

Which results in

         SASHELP.CLASS at 24. Mai 2018          

Obs    Name       Sex    Age    Height    Weight

  1    Alfred      M      14     69.0      112.5
  2    Alice       F      13     56.5       84.0
  3    Barbara     F      13     65.3       98.0
  4    Carol       F      14     62.8      102.5
  5    Henry       M      14     63.5      102.5
  6    James       M      12     57.3       83.0

 

SASnewbie2
Fluorite | Level 6

Hi Kurtbremser,

 

Can i modify from formula below 

 

%TRIM(%QSYSFUNC(DATE(), NLDATE20.)) to yesterday date 

Patrick
Opal | Level 21

@SASnewbie2

You can using spaghetti code

%put %sysfunc(sum(%sysfunc(today()),-1), nldate20. -l);
SASnewbie2
Fluorite | Level 6

SAS.png

Hi Partick,

 

Can i copy & past into the table titles as shown above ? I

 

try to run it, but it doesn't seem work. Am i miss out something ? 

Patrick
Opal | Level 21

@SASnewbie2 wrote:

SAS.png

Hi Partick,

 

Can i copy & past into the table titles as shown above ? I

 

try to run it, but it doesn't seem work. Am i miss out something ? 


 

Remove the %PUT statement. Below the bit which you need to pass in for your title

%sysfunc(sum(%sysfunc(today()),-1), nldate20. -l)
Kurt_Bremser
Super User

Oh, you need it for pointy-clicky.

 

%put is a macro statement that writes to the log; @Patrick just used it so you could see the result.

Use

%trim(%sysfunc(sum(%sysfunc(today()),-1), nldate20.))

in your title bar.

SASnewbie2
Fluorite | Level 6

Hi Patrick & KurtBremser, 

 

It works now, thanks a lots for your advice & assistance 🙂

 

Would you mind to explain why need to include the Sum( function

 

%sysfunc(sum(%sysfunc(today()),-1), nldate20.))

 

 

Kurt_Bremser
Super User

When working with the macro facility, always keep in mind it is a preprocessor for creating programs, and it only knows the datatype text, and by itself is incapable of doing calculations.

today() - 1

is just text for it, and %sysfunc accepts as its first argument only a single data step function call; the additional %sysfunc(sum()) takes care of the calculation, which would not be possible otherwise.

An alternative is the use of %eval, as in

%trim(%sysfunc(putn(%eval(%sysfunc(today())-1), nldate20.)))

My personal preference is to never use more than one %sysfunc in one line, as you can see how it tends to clutter up the code and make it harder to see the logic behind the code. Therefore my preferred method to unload such calculations into a preceding data step.

Patrick
Opal | Level 21

@SASnewbie2 wrote:

Hi Patrick & KurtBremser, 

 

It works now, thanks a lots for your advice & assistance 🙂

 

Would you mind to explain why need to include the Sum( function

 

%sysfunc(sum(%sysfunc(today()),-1), nldate20.))

 

 


 

You've got already all the explanation from @Kurt_Bremser but to say it in other words:

%sysfunc() allows you to use a single SAS data step function on SAS macro level.

We need to do two things: Call the today() function and substract a value from another value. So we need two %sysfunc() AND we need to use also a SAS function  - SUM() - for this substraction.

 

Another option would have been to use the SAS calendar function INTNX() instead of SUM() to shift the SAS date value. Something like:

%sysfunc(intnx(day,%sysfunc(today()),-1), nldate20. -l)
SASnewbie2
Fluorite | Level 6

Hi Both, 

 

Thanks a lots for your advice 🙂

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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