BookmarkSubscribeRSS Feed
HoustonGSC
Calcite | Level 5
I have the following data step that I am executing. I only want to execute it if the variable PCTFREE is below 8 percent. I have echoed the contents of PCTFREE and it is currently resolving to a numeric character of 16. Part of the code does not execute however, the attachment is still honored and sent via email.
I do not want any of the code executed if condition is not met. Is this a bug or is this a bug in my coding?

DATA _NULL_;
SET VIRB;
IF PCTFREE < 8 THEN DO;
HEADING = 'THE PROD CDAM FILES ARE ONLY '||
TRIM(LEFT(PCTFREE))||' PERCENT FREE';
/****************************************************************************/
/* THIS PORTION SENDS AN EMAIL TO WARN OF LOW THRESHOLD */
/****************************************************************************/
FILE OUTBOX EMAIL
TO='JOHNDOE@MYEMAILBOX.COM'
SUBJECT='THE SUBJECT LINE SHOULD GET OVERWRITTEN BELOW'
TYPE='TEXT/HTML'
ATTACH=('MY.OUTPUT.HTML' NAME='MYREPORT' EXT='HTM');
PUT '!EM_SUBJECT!' HEADING;
PUT 'OUT OF A TOTAL OF ' TOTCYL ' CYLINDERS, ONLY ' FREECYL
' CYLINDERS REMAIN ';
END;
RUN;
8 REPLIES 8
LinusH
Tourmaline | Level 20
Since your post doesn't contain the full code (maybe due to a bug in the forum...:http://support.sas.com/forums/thread.jspa?threadID=4138&tstart=0), log or sample data, it is hard to see you full problem. If your VIRB table just contain one observation, I would go for macro logic instead, by using %if %then %do etc.

/Linus
Data never sleeps
HoustonGSC
Calcite | Level 5
Sorry, I wasn't aware of the bug you described. Here is the code again using LT instead of the less than sign and removing all slashes.

DATA _NULL_;
SET VIRB;
IF PCTFREE LT 8 THEN DO;
HEADING = 'THE PROD CDAM FILES ARE ONLY '||
TRIM(LEFT(PCTFREE))||' PERCENT FREE';
FILE OUTBOX EMAIL
TO='JOHNDOE@MYEMAIL.COM'
SUBJECT='THE SUBJECT LINE SHOULD GET OVERWRITTEN BELOW'
TYPE='HTML'
ATTACH=('MY.OUTPUT.HTML' NAME='MYREPORT' EXT='HTM');
PUT '!EM_SUBJECT!' HEADING;
PUT 'OUT OF A TOTAL OF ' TOTCYL ' CYLINDERS, ONLY ' FREECYL
' CYLINDERS REMAIN ';
END;
RUN;
LinusH
Tourmaline | Level 20
What do you mean by "numeric character of 16"? Is PCTFREE a numeric or a character variable? What is not executed (how do you see that)? Please attach a log with a PUTLOG _ALL_; inside your DO-block.

/Linus
Data never sleeps
HoustonGSC
Calcite | Level 5
I know that PCTFREE Is a numeric character because I already did a put PCTFREE to the log to verify it was a number.

This is the listing of all the variables resulting from the PUT _ALL_

SYSID=PROD _TYPE_=0 _FREQ_=1 STORGRPS=1 VOLUMES=6 FREECYL=14,747 ALLOC=181,849 TOTCYL=196,560 PCTFREE=8 HEADING= _ERROR_=0 _N_=1

All I want to do is check the value of PCTFREE and if it falls below a threshold, then execute the logic.

I even tried changing the conditional statement to :
IF PCTFREE GT 5 THEN GO TO ALLDONE
and I put a label of ALLDONE at the end of the DO loop to see if it would bypass the email logic but it still didn't. It still executes which is puzzling.
LinusH
Tourmaline | Level 20
I tried to separate the conditional logic and the e-mail sending step into different data steps using a call execute macro call, and I think I got the behavior that you desired:

DATA _NULL_;
SET VIRB;
IF age LT 12 THEN DO;
HEADING = 'THE AGE ARE ONLY '||
TRIM(LEFT(PCTFREE ))||' !!!';
call execute('%EMAIL('||heading||','||freecyl||','||totcyl||');');
END;
RUN;

%macro email(heading,freecyl,totcyl);
data _null_;
FILE OUTBOX EMAIL
TO='JOHNDOE@MYEMAIL.COM'
SUBJECT='THE SUBJECT LINE SHOULD GET OVERWRITTEN BELOW'
TYPE='HTML'
ATTACH=('MY.OUTPUT.HTML' NAME='MYREPORT' EXT='TXT');
PUT "!EM_SUBJECT! &HEADING.";
PUT "OUT OF A TOTAL OF &TOTCYL CYLINDERS, ONLY &FREECYL CYLINDERS REMAIN ";
run;
%mend email;

Hope this helps,

Linus
Data never sleeps
HoustonGSC
Calcite | Level 5
Linus, I tried your example but when I put the macro after the data step with the conditonal test as in your example, I would get the following error:
WARNING: Apparent invocation of macro EMAIL not resolved.

If I moved the macro definition to appear before the data step with the conditional test, the sas ran fine however, the email was never sent :

MLOGIC(EMAIL): Beginning execution.
MLOGIC(EMAIL): Parameter PCTFREE has value 8
MLOGIC(EMAIL): Parameter TOTCYL has value 196560
MLOGIC(EMAIL): Parameter FREECYL has value 15488
MPRINT(EMAIL): DATA _NULL_;
SYMBOLGEN: Macro variable PCTFREE resolves to 8
MPRINT(EMAIL): PUT "!EM_SUBJECT! THE PROD CDAM FILES ARE ONLY 8 PERCENT FREE."
SYMBOLGEN: Macro variable TOTCYL resolves to 196560
SYMBOLGEN: Macro variable FREECYL resolves to 15488
MPRINT(EMAIL): PUT "OUT OF A TOTAL OF 196560 CYLS, ONLY 15488 CYLS REMAIN.";
MPRINT(EMAIL): RUN;
MLOGIC(EMAIL): Ending execution.
NOTE: There were 1 observations read from the data set WORK.VIRB.

NOTE: CALL EXECUTE generated line.
1 + DATA _NULL_;
PUT "!EM_SUBJECT! THE PROD CDAM FILES ARE ONLY 8 PERCENT FREE.";
PUT "OUT OF A TOTAL OF 196560 CYLS, ONLY 15488 CYLS REMAIN.";
RUN;

!EM_SUBJECT! THE PROD CDAM FILES ARE ONLY 8 PERCENT FREE.
OUT OF A TOTAL OF 196560 CYLS, ONLY 15488 CYLS REMAIN.


I really appreciate your time and feedback Linus but this is way more convoluted than what I think it should be. I think I'll forget about the SAS and just use REXX instead.

Thanks,
Gil.
LinusH
Tourmaline | Level 20
Yes, the macro definition has to be prior to the call. Sorry for that.
But I can't see any FILE statement in your LOG, it should appear both in the MPRINT and "NOTE: CALL EXECUTE generated line. " sections right after DATA _NULL_;
If there is no FILE statement, there will be no email...


/Linus
Data never sleeps
HoustonGSC
Calcite | Level 5
This is what the macro definition is :

OPTIONS MPRINT MLOGIC SYMBOLGEN;
%MACRO EMAIL(PCTFREE,TOTCYL,FREECYL);
DATA _NULL_;

FILE OUTBOX EMAIL
TO='JOHNDOE@MYEMAIL.COM'
TYPE='HTML'
ATTACH=('MY.FILE.HTML' NAME='MYREPORT' EXT='HTM');
PUT
"!EM_SUBJECT! THE PROD CDAM FILES ARE ONLY &PCTFREE PERCENT FREE.";
PUT
"OUT OF A TOTAL OF &TOTCYL CYLS, ONLY &FREECYL CYLS REMAIN.";
RUN;
%MEND EMAIL;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 8 replies
  • 929 views
  • 0 likes
  • 2 in conversation