Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Useful Footnote Martha Cox Population Health Research Unit Community Health & Epidemiology Dalhousie University Good morning. We've all had this happen:

Similar presentations


Presentation on theme: "A Useful Footnote Martha Cox Population Health Research Unit Community Health & Epidemiology Dalhousie University Good morning. We've all had this happen:"— Presentation transcript:

1 A Useful Footnote Martha Cox Population Health Research Unit Community Health & Epidemiology Dalhousie University Good morning. We've all had this happen: Client walks into your office with a wrinkled, coffee-stained report supposedly prepared by your group some time ago and asks you to prepare an update. Wouldn't it be nice if the report could tell you how and when it was produced, and by whom? Today I'm going to show you how to make a footnote that will do just that. In the process, I'll introduce a number of features of SAS that may be new to you. And, since John is holding me to the 10 minute "Techie Tip" timeframe, you'll get to go explore more about these new things for yourself.

2 Make the output tell you where it came from
Program Name Date and time it was submitted Who ran it So, let's say there are three things we'd like to know about this mystery output: the name of the program that produced it the date and time the program ran and the person who ran it

3 Program Name SAS system option SYSIN Specifies the default location of SAS source programs SAS function GETOPTION Returns the current value of the specified system or graphics option Start with the program name. You can use the systems option SYSIN to specify where SAS should look for source programs. But we want to get the current value of SYSIN. A SAS function called GETOPTION will do that for us. (Feature #1 to explore on your own) Functions are great if you're in the middle of a data step. But a footnote statement is not a data step. So how can we use GETOPTION? getoption(sysin) → full operating system path & filename

4 a way to execute a data step function without being in a data step
%SYSFUNC a way to execute a data step function without being in a data step If the result might contain special characters or mnemonic operators, use %QSYSFUNC instead. A SAS Macro function called %SYSFUNC can be used anywhere to execute a data step function. (Feature #2 to explore on your own) If you think the value you're retrieving might contain special characters, then %QSYSFUNC will tell the macro compiler to treat those characters as part of your text instead of responding to them. Since the full path and filename will definitely contain characters like :, /, \, or [ ], we need to use %QSYSFUNC. So . . .

5 %qsysfunc(getoption(SYSIN))
Program Name %qsysfunc(getoption(SYSIN)) This is the code for the first part of what we want.

6 Date and Time the program was submitted
The next piece of information that we want is the date and time the program was submitted. We could get this by using SAS automatic macro variables...

7 Automatic Macro Variables
&sysdate 19OCT07 &sysdate9 19OCT2007 &systime 16:22 &sysuserid MCOX &sysvlong M0P012301 SAS provides over 35 automatic macro variables that give you information about your session. (Feature #3 to explore on your own) Here are a few that we might use in our footnote. The date and time, the user who submitted it, even which version of SAS was used. Personally, I like &sysdate9 since it’s unambiguous. No worries about whether the month or the day comes first. But John hates it. So we’ll use &systime, which is in a format he likes. And I have a different method we can use for John’s date.

8 Date Submitted %sysfunc(today(), yymmddD10.)
The function TODAY() is a SAS function that returns today's date – the same value as &SYSDATE. %SYSFUNC lets us call this function and provide whatever SAS date format we want. This format gives us year-month-day using a dash as a separator. (Feature #4 to explore on your own) So the result is like the ISO 8601 date format that John favors.

9 Who Ran The Program SAS Automatic Macro Variable: &sysuserid
This variable has a length of 12. "MCOX " So to use it in a sentence, we need to trim it. The last thing we wanted to know was who ran the program. You saw on a previous slide that there's a SAS automatic macro variable which gives us this: &sysuserid. Unfortunately, SAS stores this as a character value of a specific length (I think it's 12). So we need to trim it. We already talked about calling a function. So . . .

10 %sysfunc(trim(&sysuserid))
Who Ran The Program %sysfunc(trim(&sysuserid)) . . . here's the code for our third piece. Now let's put it all together.

11 Putting it all together
proc freq data=shrug.sample; tables sex; footnote1 "Program: %qsysfunc(getoption(SYSIN)) submitted %sysfunc(today(), yymmddD10.) at &systime. by %sysfunc(trim(&sysuserid))."; run; Here's code for a simple PROC FREQ using our new footnote. Remember, when you do this, the whole string in the footnote has to be on the same line. I've broken it here so it fits on the slide.

12 The Results (VMS batch job)
The FREQ Procedure Patient Gender Cumulative Cumulative sex Frequency Percent Frequency Percent F M Program: DISK$USER1:[MCOX.SHRUG]FOOTVMS.SAS;21 submitted at 17:42 by MCOX. And here's the result. Now a few caveats. This program was run in batch on VMS.

13 Notes about Display Manager
SYSIN is blank &systime = the time you started your SAS session; not when that bit of code was run &sysuserid = the 'registered' PC user (See Control Panel → System.) If you are running your program in Display Manager mode: SYSIN will be blank because SAS is using code from the Editor window and doesn't look outside for source code Also, &SYSTIME is the time you fired up Display Manager. If you do this first thing Monday morning and leave your PC running all week, this variable isn't going to help you pinpoint when a particular program was run. If you are running on a PC, the value of &SYSUSERID will be the value of "registered user" To see what this is on your machine, go to Control Panel and click System. Mine is "PHRU6" – which doesn't really help someone figure out Martha ran the program.

14 Questions? I have a one-page handout with just the FOOTNOTE statement if you want to grab one on your way out. Any questions?


Download ppt "A Useful Footnote Martha Cox Population Health Research Unit Community Health & Epidemiology Dalhousie University Good morning. We've all had this happen:"

Similar presentations


Ads by Google