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

I'm trying to write a piece of code that will send an email out every 3 days. To do that, I'm defining a variable for today which subtracts from an anchored date (Oct 1st, 2022) which is also a variable to give me a calculated number. Then, I'll use the MODZ function and if the output of the modz function is 0, then I will send an email.

 

However, I'm getting stuck just before the modz function because although I am able to define my variables, I can't view them. The put function shows a "." in the output. This is also the case for the result of the modz function. My IF statement is then getting a "Expecting an arithmetic operator" error which may be because there is no number stored in the variable.

 

How can I get my put and modz function to output my calculation and variables instead of a period?

 

This is the code I've been using. The part I'm focusing on right now is bolded:

 

data p1;
k=today();
r=22101;
p=k-r;
;run;

 

data e1;
put r;
e=modz(p,3);
;run;


data send;
if(
e=0 then
put "send";
else
put "do not send"
;run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

There are a number of errors in your DATA SEND code.

 

There is no SET statement, so the variables in SEND are always missing. Plus other errors. And so this really has nothing to do with MODZ causing errors.

 

I would simplify your code like this:

 

data _null_;
    /* Update: Ballardw points out the 22101 is not really the date wanted */
    /* p=today()-22101; */
    /* So the fix is below */
    p=today()-'01OCT2022'd;
    e=mod(p,3);
    if e=0 then put "send";
    else put "do not send;
run; 

 

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

There are a number of errors in your DATA SEND code.

 

There is no SET statement, so the variables in SEND are always missing. Plus other errors. And so this really has nothing to do with MODZ causing errors.

 

I would simplify your code like this:

 

data _null_;
    /* Update: Ballardw points out the 22101 is not really the date wanted */
    /* p=today()-22101; */
    /* So the fix is below */
    p=today()-'01OCT2022'd;
    e=mod(p,3);
    if e=0 then put "send";
    else put "do not send;
run; 

 

 

--
Paige Miller
ballardw
Super User

You have not told this step that you want to use the data entered:

Instead of

data e1;
put r;
e=modz(p,3);
;run;

I think that you want

data e1;
   set p1;
   put r;
   e=modz(p,3);
run;

The SET statement is one of the statements to bring other data into the current data step code.

You have a similar problem here with no data source:

data send;
if(
e=0 then
put "send";
else
put "do not send"
;run;

Big problem: the numeric value 22101 you are using does not correspond to the date of 1 Oct 2022. It is actually 05JUL2020 when used with date functions. So your result would not be correct.
When you want to specify a date value then you use a date literal such as r ='01OCT2022'd; The form of the text must be in one of the formats the DATE format uses. Strongly recommend using a 4-digit year so there is never any question. The quotes, can be single or double, and the letter D immediately following tell SAS to use the value as an internal date. Also this way it is easy for a human to know the actual date intended. Five-digit dates like 22101 are most likely interpreted as Julian dates (year followed by day sequence in year) and 22101 would be mid-April. Even if you had included the leading zero for day, such as 221001, that essentially random string of digits could be 22 Oct 2001 (or 1901 depending on system settings).

So use the date literal construct.

There are similar constructs for time and datetime values.

 

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 584 views
  • 1 like
  • 3 in conversation