| Date: | Thu, 2 Mar 2000 13:56:07 -0500 |
| Reply-To: | Bob Burnham <Robert.A.Burnham@DARTMOUTH.EDU> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Bob Burnham <Robert.A.Burnham@DARTMOUTH.EDU> |
| Organization: | Dartmouth College, Hanover, NH, USA |
| Subject: | Re: Javascript from SAS |
|---|
Hi Bill,
The phrase "null variable" caught my attention in your posting. Since null
is a real value in Javascript (e.g. x = null;), I was wondering if the
program should really return an empty string instead of a null value.
I don't know if this is the best way to handle this (probably not), but I
generally test strings to see whether or not they contain the values that
I'm expecting -- rather than trying to test for a blank. Sometimes strings
have all sorts of whitespace in them, tabs, linefeeds, etc. rather than just
spaces and I usually don't care about any of them.
So, here is my pass at this. Before writing out your code to the HTML file
you can just run it through these two extremely basic macros. They both
test to see if the string contains an alphanumeric and the either the value
(formatted as a javascript string) or a null/empty string.
Good luck,
Bob
%let alphan=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;
%macro isNull(var, java);
if (indexc(upcase(&var), "&alphan") = 0) then &java = "null;";
else &java = "'" || trim(left(&var)) || "';";
%mend;
%macro isEmpty(var, java);
if (indexc(upcase(&var), "&alphan") = 0) then &java = "'';";
else &java = "'" || trim(left(&var)) || "';";
%mend;
data _null_;
length sasvar java $40;
sasvar = "";
file "test.html";
put "<HTML><SCRIPT LANGUAGE='Javascript'>";
%isEmpty(sasvar, java);
put "java = " java;
put "document.write(java);";
put "</SCRIPT></HTML>";
run;
<bill_droogendyk@DOFASCO.CA> wrote in message
news:B34F74865B47D2119E9D0000F8B84471066B5551@DFSPO02.dofasco.ca...
> SAS-L folks:
>
> Harry's using SAS to write Javascript ( as part of a web page ) and
> Javascript wants a null variable on occasion ( i.e. stuff = "" ). Since
> Harry is building this in SAS, he's saying something like:
>
> java = 'stuff = "' || sasvar || '"';
>
> If SASVAR contains only a space ( missing character variable ),
> he doesn't want the JS to say stuff = " ".
>
> (Seems like he wants to have a variable with length=0?)
>
> How can this be done in SAS???
>
> tia, on behalf of Harry, who can't SAS-L today
>
> W.(Bill) Droogendyk
> * Quality Systems
> Dofasco Inc. Hamilton ON Canada
> * Phone: 905 548 7200 x3359
> * Fax: 905 548 4007
> * Email: bill_droogendyk@dofasco.ca
|