I have a proc tabulate in a macro. Which works when run alone. It only creates a simple Tabulate output. I call this macro
%Tabulatethis;
I have a data _null_ part with put statements like:
(Which b.t.w. also works fine when run alone without the Macro).
data _null_;
file reports;
put '<!doctype html>';
put '<style>';
put '* { box-sizing: border-box; }';
put 'body { display: flex; min-height: 100vh; flex-direction: column; margin: 0; color: black } ';
put 'h1 { color: #001158 }';
put '#main { display: flex; flex: 1;}';
put '#main > article { flex: 1;}';
put '#main > nav, #main > aside { flex: 0 0 20vw; background: white;}';
put '#main > nav { order: -1;}';
put 'footer { background: #001158; color: white; height: 5vh; font-size: 10px;}';
put 'header, footer, article, nav, aside { padding: 1em;}';
put '</style>';
put '<body>';
put ' <header>';
put ' <img src="images/logo.png" alt="LOGO" width="151" height="64"> ';
put ' <h1><center>Some Title</center></h1>';
put ' <img src="images/G.PNG" alt="G" width="100%" max-width=1180px>';
put ' </header>';
put ' <div id="main">';
put ' <article><div><p></p></div>';
put ' <nav></nav>';
put ' <aside></aside>';
put ' </div>';
run;
I output everything with ODS HTML5 . All works fine. But I can't get the macro results in the HTML page 😞
I want:
to run the macro and put the output of my macro within <article><div><p> so here comes the proc tabulate results </p></div>
I Tried:
put '<article><div><p>' %Tabulatethis; '</p></div>';
Can someone please tell me why this is not working for Macro's?
Thank you.
Thank you @Tom for clearing this up. Now I understand why it keeps getting errors 🙂
So is there any other solution which could work for me?
Can I split the data _null_ set? For example:
Data _null_;
etc. etc.
put 'first html part till <p>';
run;
/*run the macro: */
%Tabulatethis;
/*then append rest of html? */
Data _null_;
etc. etc.
put 'second html part here';
run;
Or is there anything else which I can do?
What do you think these TWO statements are going to do?
put '<article><div><p>' %Tabulatethis;
'</p></div>';
Expand to see right answer.
put '<article><div><p>' PROC TABULATE
Which means write the quoted string followed by the value of the dataset variable named PROC and the dataset variable named TABULATE. Both are probably empty. Plus if the macro generates any semi-colons then the PUT statement will end and those other statements will become part of your DATA step definition.
Thank you @Tom for clearing this up. Now I understand why it keeps getting errors 🙂
So is there any other solution which could work for me?
Can I split the data _null_ set? For example:
Data _null_;
etc. etc.
put 'first html part till <p>';
run;
/*run the macro: */
%Tabulatethis;
/*then append rest of html? */
Data _null_;
etc. etc.
put 'second html part here';
run;
Or is there anything else which I can do?
It may be time to clearly state what the objective overall is.
You have not shared what the macro looks like so we can't tell if the possible split of your data _null_ would work or not. Consider what Tabulate generates. Is the output sent to file, result window, output window? If the macro is generating a plain text file then it MAY work with the data _null_ as proposed.
If the output of the macro is an HTML(5) file then perhaps you would use a HREF or similar using the URL for the file.
Possibly PROC Document, which is designed to rearrange SAS output, could be of use.
@SAS_Question wrote:
Thank you @Tom for clearing this up. Now I understand why it keeps getting errors 🙂
So is there any other solution which could work for me?
Can I split the data _null_ set? For example:
Data _null_; etc. etc. put 'first html part till <p>'; run; /*run the macro: */ %Tabulatethis; /*then append rest of html? */ Data _null_; etc. etc. put 'second html part here'; run;
Or is there anything else which I can do?
This is not the nicest, easiest, or most maintainable way to write HTML!
If you'd like to put an end to put statements, you may consider the SASjs framework. We have built a compilation mechanism that lets you embed arbitrary files in SAS programs. Our latest release actually lets you embed binary files also (so you could put images, excel files, or zip files, INSIDE a textual SAS program).
A demo of this is available here.
To make this work for your particular use case:
* stick your HTML in the /programs folder
* add it under the `<h4> SAS Includes </h4>` program header
* run `sasjs compile`
It is now automatically wrapped in put statements, with each line no longer than 220 characters in length.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: