DATA Step, Macro, Functions and more

include sas code in results ?

Occasional Learner
Posts: 1

include sas code in results ?

I am trying to locate a way to export my sas code into my results.   The purpose: create study notes in a SAS course I am taking, so that I can end up with the assigned task in the comments, the code I used, and the results. 


Example of what I need to do - I would like all of the below to appear in my results - the comment, the code, plus the results:




Question 1: Figure out the mean and median weight from the data sashelp.bweight. 


proc means data=sashelp.bweight Mean Median;

var weight;



The SAS System

The MEANS Procedure

Analysis Variable : weight









Super User
Posts: 10,778

Re: include sas code in results ?

[ Edited ]
Posted in reply to CarolynNorman

Assuming is the code you are running.



filename x '/folders/myfolders/';
data x;
infile x length=len;
input x $varying256. len;
proc report data=x nowd noheader style={ rules=none frame=void asis=on};
%include x / source2;


Super User
Super User
Posts: 9,599

Re: include sas code in results ?

Posted in reply to CarolynNorman

To me it sounds like your doing things the wrong way round.  First come the specifications, then the coding.  To put it another way, 90% of programming activites is documentation - specifcations, testing logs, help documentations etc.  The actual putting some code down is a very small part of it.  Your doing the reverse, your trying to create documentation from what you have coded.  This will not work on at least two fronts.  First you can't test the code, as you only know what it does, not what it should do.  Secondly change management, changes will never be captured as the documentation always shows what has run, no comparisons.

To be honest, if your metadata (specifcations) is robust enough, you don't even need to program, just generate the code directly.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation