SAS Formats and

SAS Formats and SAS Formats and - Start

Added : 2017-05-15 Views :92K

Download Presentation

SAS Formats and




Download Presentation - The PPT/PDF document "SAS Formats and" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.



Presentations text content in SAS Formats and

Slide1

SAS Formats and

SAS Macro Language

HRP223 – 2011November 9th, 2011

Copyright ©

1999-2011

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.

Slide2

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.

Slide3

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.

Slide4

Sharing Files

If everyone on your team uses the same version of SAS you can send datasets and catalogs via encrypted email. 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;1 83 12 82 0;run;

Slide5

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 email).proc cport library = cportEx file="C:\Projects\hrp223\cportExample\example.cport" memtype = all;run;

Send this one.

Slide6

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;

Slide7

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

;

Slide8

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.

Slide9

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.

Slide10

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.

Slide11

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.

Slide12

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:

Slide13

Create a prompt

Slide14

Choose a variable list

Choose the dataset with the variable names

Slide15

Delete the subject variable

The prompt is available for the project.

Slide16

Note the typo…

Slide17

Edit the typo…

Slide18

The code

The “ and “n are not needed.

Note the trailing decimal. Always use it.

My version is simpler.

Slide19

Note the ?

Slide20

It works….

Slide21

Pure code… without the prompt

This will be set for the entire SAS session. Most dangerous!

Slide22

Notice no & and .

Notice the & and .

Slide23

Macros can do many tasks.

Slide24

Macro Details

Macros begin with the word… macro and

end

with the word m

end

.

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.

Slide25

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.

Slide26

Other Examples

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

Slide27

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.

Slide28

Sensitivity, Specificity, Positive and Negative Predicted Value

Somehow SAS forgot them…

In the log

In the log

Slide29

Binomial Probabilities

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

Slide30

Slide31

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.

Slide32

Original

Macro variables

Slide33

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.

Slide34

You can define default values

You can define default and you can override the defaults.


About DocSlides
DocSlides allows users to easily upload and share presentations, PDF documents, and images.Share your documents with the world , watch,share and upload any time you want. How can you benefit from using DocSlides? DocSlides consists documents from individuals and organizations on topics ranging from technology and business to travel, health, and education. Find and search for what interests you, and learn from people and more. You can also download DocSlides to read or reference later.
Youtube