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?
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.
@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.
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.
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.
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.
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...
@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.
Check out the ODS Layout options:
especially epub3
https://support.sas.com/resources/papers/proceedings14/SAS339-2014.pdf
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.