Date: Wed, 6 Jul 2011 21:52:42 -0700
Reply-To: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Subject: Re: user-generated error messages
In-Reply-To: <CAEZCyssNPjzHXbKYv1raMpDZrDxV4xso5WxYDUj7N7BrBjS9NQ@mail.gmail.com>
Content-Type: text/plain; charset=us-ascii
OK, I should have known better. But
=====
41 data _null_;
42 errmsg = ':RORRE';
43 put errmsg $revers7. 'bad stuff';
44 run;
ERROR: bad stuff
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
=====
On Jul 6, 2011, at 8:02 PM, Data _null_; wrote:
> Well no.
>
> 1874 data _null_;
> 1875 put ":RORRE" $REVERJ6. 'rest of message';
> ---------
> 22
> ERROR 22-322: Expecting a name.
>
> 1876 run;
>
> NOTE: The SAS System stopped processing this step because of errors.
>
>
> On Wed, Jul 6, 2011 at 8:29 PM, Jack Hamilton <jfh@stanfordalumni.org> wrote:
>> I haven't tried it, but would
>>
>> put ":RORRE" $reverse 'rest of message';
>>
>> work?
>>
>> On Jul 6, 2011, at 9:11 AM, Quentin McMullen wrote:
>>
>>> Hi All,
>>>
>>> I'm in the habit of writing user-generated error messages to the log,
>>> e.g. when I encounter some unexpected condition in a dataset.
>>> Something like:
>>>
>>> data _null_ ;
>>> if 1 then put "ERROR: Something bad happened ";
>>> run;
>>>
>>> This prints a nice error message to the log, it's highlighted with
>>> appropriate coloring, etc.
>>>
>>> I don't like to have the word "error" in my code. Although I love my
>>> %logcheck macro, there are folks who use my code who might think they
>>> can check a log by hitting searching for the string "ERROR", and if
>>> they do that, they will find lots of false positives in my log, every
>>> time I write the word ERROR. So my hack (I think picked up from SAS-L
>>> years ago, though I also remember several SAS-L'ers thinking this is
>>> way too ugly for their taste...) has been to code:
>>>
>>> if 1 then put "ER" "ROR: Something bad happened ";
>>>
>>> If the put statement executes, ERROR: will be written to the log,
>>> without ERROR appearing in my code. Again, the ugliness of the code
>>> may be too much for many people's taste, but I don't mind it....
>>>
>>> The above works until I have a long error message. If I code:
>>>
>>> if 1 then put "ER" "ROR: Something %sysfunc(repeat(%str(REALY ),20
>>> )) bad happened";
>>>
>>> Then the line generated by the PUT statement is too long and is forced
>>> to wrap, and I get ER on one line followed by ROR on second line,
>>> i.e.:
>>>
>>> 54 data _null_ ;
>>> 55 if 1 then put "ER" "ROR: Something %sysfunc(repeat(%str(REALY
>>> ),20 )) bad happened";
>>> 56 run;
>>>
>>> ER
>>> ROR: Something REALY REALY REALY REALY REALY REALY REALY REALY REALY
>>> REALY REALY REALY REALY REA
>>> LY REALY REALY REALY REALY REALY REALY REALY bad happened
>>>
>>> That seems fair, but of course means I won't get ERROR: in the log, so
>>> I'm in trouble.
>>>
>>> My thought was that I could change to add separate quotes for the
>>> error message. This sems to assure that ERROR: appears on one line.
>>> The down side being that the explanatory text is on the next line, but
>>> not the end of the world.
>>>
>>> if 1 then put "ER" "ROR: " "Something %sysfunc(repeat(%str(REALY
>>> ),20 )) bad happened";
>>>
>>> 58 data _null_ ;
>>> 59 if 1 then put "ER" "ROR: " "Something
>>> %sysfunc(repeat(%str(REALY ),20 )) bad happened";
>>> 60 run;
>>>
>>> ERROR:
>>> Something REALY REALY REALY REALY REALY REALY REALY REALY REALY REALY
>>> REALY REALY REALY REALY RE
>>> ALY REALY REALY REALY REALY REALY REALY bad happened
>>>
>>>
>>> But it's still not pretty. And if I take that approach, I would
>>> actually just assign a Function key to write:
>>> put "ER" "ROR: USER " " ";
>>> and since often I'm too lazy to write a detailed error message, that
>>> line would be all over my code, looking very odd (but working as I
>>> intend it).
>>>
>>> My other thought was to use a macro null to break up the SAS code:
>>>
>>> data _null_ ;
>>> if 1 then put "ER%str()ROR: USER Something
>>> %sysfunc(repeat(%str(REALY ),20 )) bad happened";
>>> run;
>>>
>>> That works in open code. But if that step is generated by a macro and
>>> mprint is on, I'm back to the situation where ERROR: occurrs in the
>>> log just because the word occcurs in my code.
>>>
>>>
>>> So I'm leaning towards changing by function key to be:
>>> put "ER" "ROR: USER " " ";
>>>
>>> But before I proceed down that path, was wondering if anyone here
>>> would talk me out of it.
>>>
>>> Again, by goal is to write ERROR: messages (and WARNING: messages) to
>>> the log, without having the word ERROR show up in my code. So that if
>>> someone searches a log for the word ERROR, they will only get a hit if
>>> there is actually an ERROR in the log. (And yes, sometimes I've
>>> even done silly stuff like options mergenoby=ER%str()ROR ; but I think
>>> that's taken things a bit too far...)
>>>
>>> Kind Regards,
>>> --Quentin
>>
|