DATA Step, Macro, Functions and more

data _null_ file and html code

Posts: 0

data _null_ file and html code

I'm currently using data _null_ file reports to insert dynamic html code.
I'm placing a put statement before each line of code (there are 70 lines of code).
I have two questions:
1) Is there a better way to write html code in SAS than using put statements before each line?
2) How do I fix the quotation marks on the next three lines of code to make it run (the error occurs on the line with mycountainer.innerHTML)? The html code is correct by itself, but when I add the put statements for these last few lines I get an error due to the single quotation marks needed for the put command.

put ' var mycountainer=document.getElementById("cpcontainer")';
put ' mycountainer.innerHTML="Days since last injury:
"+result['days']+" days "+result['hours']+" hours "+result['minutes']+" minutes "+result['seconds']+" seconds"';
put '}';
put '';

Thank you.
Respected Advisor
Posts: 3,894

Re: data _null_ file and html code

It's a pain but you will have to quote double quotes with single quotes and single quotes with double quotes. Something like this:

put "xxx 'and this in single quotes' xxx" ' yyy "and this in doubles quotes" yyy';

or this way:
put "xxx 'and this in single quotes' xxx" @;
put 'yyy "and this in doubles quotes" yyy';

As much as I know there is not really an easier way with SAS of creating this kind of html you seem to aim for.
One possibility would be to have your html code in an external file, using tokens for the parts SAS should replace and then using something like:

data _null_;
infile ....;
file ....;
put _infile_;

You could also use more than one data step, let's say the first and the last write the header and "footer" section of you html which is normaly static, the middle part writes the dynamic section.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation