SAS proc odstext procedure

Reply
Occasional Contributor
Posts: 6

SAS proc odstext procedure

I have a problem with appending html code to existing file using proc odstext. Anyone can help?

Grand Advisor
Posts: 10,223

Re: SAS proc odstext procedure

Please describe the type of problem. Is the text not appending at all, in the location, the text is incorrect or not formatted as desired, missing tags, replacing the file instead of appending or something else.

Also provide an example of the code used.

Occasional Contributor
Posts: 6

Re: SAS proc odstext procedure

I've created a macro:


%macro append(text);

        ods html close;

        options nodate;

        ods html file = "test.html";

        proc odstext;

               p "My name is " || &text.;

               end;

        run;

        ods _all_ close;

    options &_options;

%mend;

%append('Tom');

%append('Mike');


I'd like to append one odstext to existing html. The result should be:

My name is Tom

My name is Mike


Unfortunately, only one sentence is created:

My name is Mike.


How can I append next text value to the other in html file using proc odstext? Instead of replacing html file.

Grand Advisor
Posts: 10,223

Re: SAS proc odstext procedure

Your current macro code opens a file (ODS HTML), writes some output (Proc odstext) and then closes the file(ods _all_ close). Since you are reusing the same file name the last output overwrites the previous file resulting in only the last call existing in the file.

You would need to open the file, generate ALL of the text, then close the file.

You could do something like:

ods html file = "test.html";

        %outputmacro('Tom');

         %outputmacro('Mike');

        ods _all_ close;

or pass a list of values and generate output for each of them. Search the forum for macro list processing as this is a common activity.

Occasional Contributor
Posts: 6

Re: SAS proc odstext procedure

Thanks, but it's not what i want. In this case, I'd like to append new values and not delete previous one. And it can't  be done in one step as you suggested. Anyone?

Grand Advisor
Posts: 10,223

Re: SAS proc odstext procedure

Did you have a working process before you started to make a macro?

Does this create what you want?

ods html file = "test.html";

        proc odstext;

               p "My name is Mike".;

               end;

        run;

        proc odstext;

               p "My name is Tom".;

               end;

        run;

        ods _all_ close;

as far as sending multiple outputs to the same file?

If not, them may want to expand on your requirement a bit more. If you have an existing file that existed before you start the SAS code you will need to very carefully explain exactly what is actually needed because anything that starts with a simple ODS html statement will overwrite the existing file.

Occasional Contributor
Posts: 6

Re: SAS proc odstext procedure

No... These two names were only examples. The main idea was to run macro n-times with different parameters like Tom, Lucy etc. Then, after refresh in html file in browser there will be a list of sentences with names. Using proc odstext.

Grand Advisor
Posts: 10,223

Re: SAS proc odstext procedure

You might investigate putting the values into a data set and then displaying each line generated that way. Macro not needed.

Occasional Contributor
Posts: 6

Re: SAS proc odstext procedure

No, because I have to use html

Super User
Super User
Posts: 6,364

Re: SAS proc odstext procedure

I doubt that you can use ODS to append to an existing HTML file.

You can however keep the ODS output open and continue to write output to it.

Occasional Contributor
Posts: 6

Re: SAS proc odstext procedure

Even update of html file using ods is not allowed? When I close the html file, there is no way to add new elements using ods?

Esteemed Advisor
Esteemed Advisor
Posts: 7,241

Re: SAS proc odstext procedure

As Tom has stated, you are not able to just append text to HTML.  The reason is that whilst HTML is a text file, it is a tagged file, which is rendered by other software.  If you open the first HTML file generated in notepad, you will see lots of other information, and lots of tags <xyz> before and after the text.  You need to understand the HTML language, and whilst you can "append", you would need to know where in the HTML document to place your additional text, and what tags to add around it. 

So, take a very simple example with virtually nothing in the file:

<!DOCTYPE html>
<html>
<head>
  <title>Hi there</title>
</head>
<body>
  This is a page
  a simple page
</body>
</html>


In this example, to add the text "Hi" to the "file", I would need to find the end tag </body> and then before writing the tag out, write my text, then write the tag:

<!DOCTYPE html>

<html>

<head>

  <title>Hi there</title>

</head>

<body>

  This is a page

  a simple page

  Hi

</body>

</html>

So best to start by understanding what HTML is:

HTML Examples

Ask a Question
Discussion stats
  • 11 replies
  • 323 views
  • 0 likes
  • 4 in conversation