1 SAS Formats and SAS Macro Language HRP223 – 2011 November 9 th, 2011 Copyright © 1999-2011 Leland Stanford Junior University. All rights reserved. Warning:

Slides:



Advertisements
Similar presentations
The SAS ® System Additional Information on Statistical Analysis Programming.
Advertisements

The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Tutorial 8: Developing an Excel Application
Final Thoughts HRP 223 – 2013 December 4 th, 2013 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation.
1 Appendix A: Writing and Submitting SAS ® Programs A.1 Writing and Submitting SAS Programs.
Raymond R. Balise Health Research and Policy
Working with Data in Windows HRP223 – 2010 October 4 th, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
1 Merging with SQL HRP223 – 2011 October 31, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation.
1 Lab 2 HRP223 – 2010 October 18, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
1 Processing Grouped Data HRP223 – 2011 November 14 th, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
1 Combining (with SQL) HRP223 – 2010 October 27, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation.
1 Creating and Tweaking Data HRP223 – 2010 October 24, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
1 Database Theory and Normalization HRP223 – 2010 November 14 th, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning:
1 Lab 1 HRP223 – 2011 Oct 10, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
Permanent Formats and Working Across Platforms. 32bit vs. 64 bit SAS The different versions of SAS optimize datasets and formats to work as fast as possible.
1 An Introduction to IBM SPSS PSY450 Experimental Psychology Dr. Dwight Hennessy.
1 Windows and Beginning Data Manipulation HRP223 – 2013 Oct 9, 2012 Copyright © Leland Stanford Junior University. All rights reserved. Warning:
SAS for Categorical Data Copyright © 2004 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright.
Copyright © 2006, SAS Institute Inc. All rights reserved. Enterprise Guide 4.2 : A Primer SHRUG : Spring 2010 Presented by: Josée Ranger-Lacroix SAS Institute.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and international.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Intro to By Debra Dimas Special thanks to David Fogliatti and Armand Amarento of Oceanside HS in San Diego.
HPR Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
Working with Data in Windows HRP223 – 2009 Sept 28 th, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
5/30/2010 SAS Macro Language Group 6 Pradnya Nimkar, Li Lin, Linsong Zhang & Loc Tran.
1 Lab 2 and Merging Data (with SQL) HRP223 – 2009 October 19, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning:
June 12, 2009 Toronto Area SAS Society 1 What’s new in BASE SAS 9.2 Checkpoint/Restart Rupinder Dhillon Dhillon Consulting Inc.
Diagnostic Pathfinder for Instructors. Diagnostic Pathfinder Local File vs. Database Normal operations Expert operations Admin operations.
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and international.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
1 Lab 1 HRP223 – 2011 Oct 10, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
1 Lab 1 HRP223 – 2009 October 5, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
HRP 223 – 2007 lm.ppt - Linear Models Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
1 Data Manipulation (with SQL) HRP223 – 2009 October 12, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Chavez, Melesan Karen De Luna, Lin Detera, Patrick Kevin Martinez, Jellene Joy Dental Clinic Database System Functional Requirements.
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
Beginning Data Manipulation HRP Topic 4 Oct 14 th 2012 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and international.
SQL and SQL*Plus Interaction
SAS Programming Introduction to SAS.
Working with Data in Windows
SAS Output Delivery System
UNITY TEAM PROJECT TOPICS: [1]. Unity Collaborate
Combining (with SQL) HRP223 – 2013 October 30, 2013
Lab 3 and HRP259 Lab and Combining (with SQL)
Lab 2 and Merging Data (with SQL)
Combining (with SQL) HRP223 – 2012 November 05, 2011
Lab 2 HRP223 – 2010 October 18, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
Stata Basic Course Lab 2.
Lab 1 HRP223 – 2009 October 5, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
A Bit About SAS/Macro Language Database Theory and Normalization
File Sharing and Processing Grouped Data
Data Manipulation (with SQL)
Processing Grouped Data
Presentation transcript:

1 SAS Formats and SAS Macro Language HRP223 – 2011 November 9 th, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and international treaties. Unauthorized reproduction of this presentation, or any portion of it, may result in severe civil and criminal penalties and will be prosecuted to maximum extent possible under the law.

2 Formats Saved in Libraries * x "mkdir C:\Projects\hrp223\cportExample"; libname cportex "c:\projects\hrp223\cportexample"; proc format library = cportEx; value isMale 0 = "Female" 1 = "Male". = "Missing" other = "** bad **" ; run; Save the format here instead of in work. SAS is pushing this idea.

3 Where to Find Formats SAS and EG look for formats in the work library. You can tell it to look in other libraries with a line like this: options fmtsearch = (cportEx work); Your library name goes here.

4 Sharing Files If everyone on your team uses the same version of SAS you can send datasets and catalogs via encrypted . Send both the files in the library and teach the recipient about options fmtsearch. data cportEx.stuff; format sex isMale.; input ID age sex; datalines; ; run;

5 proc cport If you need to share datasets and formats across platforms (including 32 vs 64 bit Windows SAS), store the library in cport file and send that (via encrypted ). proc cport library = cportEx file="C:\Projects\hrp223\cportExample\example.cport" memtype = all; run; Send this one.

6 proc cimport Use proc cimport on the other machine: libname cportEx "C:\Projects\hrp223\cportExample"; options fmtsearch = (cportEx work); proc cimport library = cportEx file = "C:\Projects\hrp223\cportExample\example.cport" ; run;

7 No Formats… If somebody forgets to send you the formats you can include this line and the data will display unformatted without errors: options nofmterr;

8 32bit vs. 64 bit SAS The different versions of SAS optimize datasets and formats to work as fast as possible. You can open a 32 bit SAS dataset with a 64 bit version of SAS but it is slower than necessary. Formats saved in permanent libraries (as catalogs) may have problems opening on different platforms/operating systems.

9 And now for something completely different… Macros Early in the class I told you to download my keyboard macros. Those auto-complete SAS codes as you type into the editor. Keyboard macros are not what SAS people call Macros. Macros are programs that do automated tasks. Rather than having to reinvent solutions to complex problems, SAS programmers keep libraries of useful code in easy to use macro format.

10 I want…. Bar charts are the wrong way to display data if you have tiny samples. I want a plot to show the mean value as a red bar and the individual data points around it. This requires fairly complicated voodoo and I want to be able to reuse the code.

11 I create the plot once then tweak it to turn it into a macro. This is like a user-defined function. %plotit(w2, weight, group, 4, group1=Thing1, group2=Thing2, group3=Thing3, group4=Thing4); Here is the call that makes this plot.

12 Prompts The macro “call” is like prompting a user to fill in the details for the required “arguments”. I have a dataset and I want EG to ask the user to what variable to analyze:

13 Create a prompt

14 Choose a variable list Choose the dataset with the variable names

15 Delete the subject variable The prompt is available for the project.

16 Note the typo…

17 Edit the typo…

18 The code The “ and “n are not needed. Note the trailing decimal. Always use it. My version is simpler.

19 Note the ?

20 It works….

21 Pure code… without the prompt This will be set for the entire SAS session. Most dangerous!

22 Notice no & and. Notice the & and.

23 Macros can do many tasks.

24 Macro Details Macros begin with the word… macro and end with the word mend. As a user of the macro, you can ignore everything after the first line. The first line has the parameters (aka arguments) that the macro needs. Hopefully the person who wrote the macro will give you the details on the arguments. – The parameters are filled in using the order you typed them unless the arguments have names.

25 Definition of the plotit macro is here. This creates the macro but does not cause it to do anything. Expand the code if and only if you want to. Arguments are hopefully well named. They are a comma delimited list. Macros typically arrive with a big comment to explain what you use for the arguments This calls/invokes the plotit macro. The macro is actually “done” when you include a line like this.

26 Other Examples I want to make a quantile plot to show the percentiles for a dataset.

27 Run the macros once. You can then invoke the macro repeatedly. The code may be hardcore but you only need to figure out the comments.

28 Sensitivity, Specificity, Positive and Negative Predicted Value Somehow SAS forgot them… In the log

29 Binomial Probabilities If you need to calculate binomial probabilities look at my macro:

30

31 How to Create a Macro Get code that works either by manually writing it or looking at the code that EG generates. Identify the things that you want to change with different runs of the macro. Replace the those keywords with a name preceded by an & and followed by a. Enclose the edited code with inside of %macro(); and mend; Insert your macro variables as a comma delimited list inside the () on the macro line.

32 Original Macro variables

33 Original Add the wrapper. Add names of the macro variables notice you do NOT put & and. In the list of arguments. Now you can call the macro.

34 You can define default values You can define default and you can override the defaults.