BookmarkSubscribeRSS Feed
LauraRK
Quartz | Level 8

Is there SAS code that creates attractive documents like the SAS online help, https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=statug&docsetTarget=statu...

or is the SAS online help created outside of SAS?  I like how in the online help there is little code snippets and the ability to copy those snippets and that it looks attractive and keeps the color coding. 

 

I have a little macro,

%macro echocode(sasfile=sasprogram);
Proc document name=temp(write) ;
Import textfile="&projdir\&sasfile..sas" to ^;
Run;
Replay;
Run;
Quit;
%include "&projdir.\&sasfile..sas";
%mend;

but the code is  not nicely formated.  I tried to further develop my own system to divide up my code but I still had some issues, mainly I can't figure out ways to keep the tabs.  I really want an Rmarkdown type solution.   I could connect Rstudio to SAS, but I would rather program in SAS studio or SAS EG when I write SAS code.  I learned Statrep, but I feel there must be an easier way to do this that does not involve using latex, I like latex, but in my classes that use R, I literally can give students an Rmarkdown document on the first day and have them knit it and make a nice document with code and output and I keep thinking there must be a way I could set this up in SAS as well that is not so complicated?  Am I missing something obvious?

 

 

12 REPLIES 12
LauraRK
Quartz | Level 8

Thank you Reeza.  I am looking for an approach that works from within a SAS programming environment, such as SAS EG or SAS studio. I would rather use Rstudio (https://www.ssc.wisc.edu/~hemken/SASworkshops/Markdown/SASmarkdown.html  ) or Latex with Statrep than Jupyter notebooks if I use a non-SAS programming environment solution.  

 

I like the SAS help documents which look like they are available as edocuments, html and pdf, so I wonder how those are coded?  If they are not coded from within SAS using ODS then I will give up or keep working myself on the problem.  

 

 

ballardw
Super User

@LauraRK wrote:

Is there SAS code that creates attractive documents like the SAS online help, https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=statug&docsetTarget=statu...

or is the SAS online help created outside of SAS?  I like how in the online help there is little code snippets and the ability to copy those snippets and that it looks attractive and keeps the color coding. 

 

I have a little macro,

%macro echocode(sasfile=sasprogram);
Proc document name=temp(write) ;
Import textfile="&projdir\&sasfile..sas" to ^;
Run;
Replay;
Run;
Quit;
%include "&projdir.\&sasfile..sas";
%mend;

but the code is  not nicely formated.  I tried to further develop my own system to divide up my code but I still had some issues, mainly I can't figure out ways to keep the tabs.  I really want an Rmarkdown type solution.   I could connect Rstudio to SAS, but I would rather program in SAS studio or SAS EG when I write SAS code.  I learned Statrep, but I feel there must be an easier way to do this that does not involve using latex, I like latex, but in my classes that use R, I literally can give students an Rmarkdown document on the first day and have them knit it and make a nice document with code and output and I keep thinking there must be a way I could set this up in SAS as well that is not so complicated?  Am I missing something obvious?

 

 


You say the "code is not nicely formatted". Can provide more details on what "nicely formatted" actually means in this context?  By "keep the tabs" do you mean tab characters in the source .SAS file?

Also the font in the created document may not align things like a monospace font would.

 

 

Is the SAS text program file "nicely formatted" before import? The text files are pretty much as read though long lines may get broken to fit the display format.

LauraRK
Quartz | Level 8

Hi,

So minimally I would like there to be indents as written the code ends up without indents in the report.

I will keep working on it if this is the best approach.  I have a macro to divide a bigger program up, then this macro to print the code. 

My code blocks end up without tabs, so they are all lined up on the left.  Like the below. 

proc univariate data=ch4.gas;
histogram gasprice/ odstitle="Average Gas Prices";
inset n mean(5.1) median std(5.1) min max /position=NE;
run;

What I want

proc univariate data=ch4.gas;
 	histogram gasprice/ odstitle="Average Gas Prices";
 	inset n mean(5.1) median std(5.1) min max
	/position=NE;
run;

Ideally it would be like SAS online help and also include colors but I can live without that.   If I should stick with the approach I am using and work to make my own macros I will go ahead but I just wanted to first make sure there was not something obvious I was missing and at least fix this tab problem.

 

 

 

ballardw
Super User

If the source file doesn't have indents Proc Document isn't going to help.

My test involved a SAS program that is saved with the option to turn tabs into spaces, because TABS as such are just waiting to be problems, and that maintained the indents.

 

Different files/programs interpret tabs to be of differing numbers of character spaces and the output can be very unreliable as far as maintaining a specific alignment. I've dealt with this often enough that given a choice I will get rid of tabs in program files and leave it to word processing to use tabs.

LauraRK
Quartz | Level 8
The source file does have indents. When I and many others code we tend to hit "tab" and ctrl-I in SAS EG to "format code" puts in tabs. I mostly was asking here because if there was away to create online documentation such as what we see in SAS help, and I was able to get an example of how they are doing that and it was done using SAS that would be great.
Reeza
Super User
Honestly don't think a good way exists, or at least not one that I know of. I'm a huge fan of RMarkdown and Bookdown myself so I understand the desire for similar functionality when teaching or prepping for courses. I've found that Jupyter Notebooks gives me about 80% of what I want but the rest I usually use standard markdown. Took a look at the SASMarkdown package you mentioned but the batch issue of that would be annoying.
LauraRK
Quartz | Level 8

Thanks Reeza.  Maybe I will try Jupyter but last time I tried it I found it frustrating, maybe because as of yet I do not use Python.  I just have started really embracing the Rstudio workflow and followed Mine Centinkaya Rundel's Data Science in a Box https://datasciencebox.org/index.html and have been really happy with that but I do still teach some classes with SAS as well.

Reeza
Super User
I don't use Python as a main language, just R and SAS as well - I find their communities (online & in person) are a lot more friendly, inclusive and helpful. I believe Jupyter Studio is also supported but I'm not familiar with it.
Reeza
Super User

One thing that SAS does well, it allows you to provide feedback. 

I've added a brief suggestion here - if you wanted to expand your requirements in the comments section SAS will consider the addition at some point...

 

https://communities.sas.com/t5/SASware-Ballot-Ideas/Markdown-support-to-allow-for-inclusion-of-code-...

ballardw
Super User

@LauraRK wrote:

Hi,

So minimally I would like there to be indents as written the code ends up without indents in the report.

I will keep working on it if this is the best approach.  I have a macro to divide a bigger program up, then this macro to print the code. 

My code blocks end up without tabs, so they are all lined up on the left.  Like the below. 

proc univariate data=ch4.gas;
histogram gasprice/ odstitle="Average Gas Prices";
inset n mean(5.1) median std(5.1) min max /position=NE;
run;

What I want

proc univariate data=ch4.gas;
 	histogram gasprice/ odstitle="Average Gas Prices";
 	inset n mean(5.1) median std(5.1) min max
	/position=NE;
run;

Ideally it would be like SAS online help and also include colors but I can live without that.   If I should stick with the approach I am using and work to make my own macros I will go ahead but I just wanted to first make sure there was not something obvious I was missing and at least fix this tab problem.

 

 

 


One suspects if the source file had spaces that either the macro code removes them or doesn't like tab characters. It is very likely that your macro is removing the formatting.

Share the macro code that 'divides a bigger program up' and perhaps we can fix that part.

 

Also what destination are you sending the Proc document output to? It is possible that some of the behavior is ODS destination dependent.

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
  • 12 replies
  • 1597 views
  • 4 likes
  • 4 in conversation