BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_Question
Quartz | Level 8

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.  

1 ACCEPTED SOLUTION

Accepted Solutions
SAS_Question
Quartz | Level 8

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? 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

What do you think these TWO statements are going to do?

 

put '<article><div><p>'  %Tabulatethis; 
'</p></div>';

Expand to see right answer.

Spoiler
Any SAS code the macro generates will be inserted into the middle of the PUT statement.  So if the first text that the macro generates is PROC TABULATE then your PUT statement will  start with:
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.

The second statement after the semi-colon is clearly not a valid SAS statement as it is just a string literal.

 

SAS_Question
Quartz | Level 8

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? 

ballardw
Super User

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? 


 

AllanBowe
Barite | Level 11

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.

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 710 views
  • 0 likes
  • 4 in conversation