sas tips and tricks group... · 2017. 5. 18. · sas tips and tricks april 2017 doug dover senior...

31
SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance Alberta Health

Upload: others

Post on 22-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

SAS Tips and Tricks

April 2017

Doug Dover

Senior Methodologist

Epidemiology and Surveillance

Alberta Health

Page 2: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Today…

1. Importing Data

2. SAS Studio

Page 3: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

1. Importing Data

Page 4: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

I hate importing data.

Page 5: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

I hate importing data.

Page 6: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

I still hate importing data.

Page 7: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

The Process

Proc Import out=survey

DATAFILE="M:\survey.sav"

DBMS=SPSS REPLACE;

run;

Page 8: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

The Process Broke

1,032 variables????

There should only be 246.

Page 9: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

A Side Note on The Process

Proc Import out=survey

DATAFILE="M:\20161205.sav"

DBMS=SPSS REPLACE;

run;

Nice thing: this saved formats!

Page 10: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Fixing what Broke

Tried exporting in different formats…

.sav formats & extra vars

.xlsx NULL problem

.sas7bdat no formats

.csv no formats

.dbf half the variables

.dta works! (mostly)

Page 11: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Switching to STATA .dta for import

Missing values were all -9998

Page 12: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Switching to STATA .dta for import

Data survey;

Set survey;

Array change{*} _numeric_ ;

do i = 1 to dim(change);

if change{i} = -9998 then change{i} = . ;

end;

drop i;

run;

Page 13: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

What if….

• I wasn’t able to find a export format that

worked?

• How could I get the correct variables AND

the formats?

Page 14: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

What if….

• How could I get the correct variables AND

the formats?

Formats

Data Integrity

Issues

Data

Page 15: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

1. Read in the No Format file

Data NoFormats;

Set survey.survey;

run;

Data

Page 16: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

2. Import the SPSS file with formats

but extra variables

Proc Import out=ExtraVars

datafile=“M:\survey.sav”

DBMS=SPSS replace;

run;

Formats

Data Integrity

Issues

Page 17: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

3. List the keep variables

Proc Contents Data = NoFormats

out = vars (keep = varnum name)

noprint;

run;

Page 18: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

3. Keep variables in macro variable

Proc SQL noprint;

select distinct name

into :varlist separated by ' '

from vars

;

quit;

Page 19: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

4. Put it all together awesomeness!

Data survey;

Set ExtraVars ( obs=0 )

NoFormat

;

keep &varlist;

run;

Page 20: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

2. SAS Studio

Page 21: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

What is SAS Studio?

• Classic SAS + EG all in one

• Throwback to the 1960s?

Page 22: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

What is SAS Studio?

Page 23: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

What is SAS Studio?

Page 24: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Random things I’ve learned using

SAS Studio

• It has two interfaces –

programmer and visual

programmer

• I’ve only tried one

Page 25: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Random things I’ve learned using

SAS Studio

Programming interface has two

modes:

• Interactive

• Batch

Page 26: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Random things I’ve learned using

SAS Studio

Can switch between:

• Interactive

• Classic SAS

• Batch

• If you highlight and run

when developing code,

this won’t work for you

Page 27: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Random things I’ve learned using

SAS Studio

You can Batch submit once again!

• Ah, my youth…

Page 28: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Random things I’ve learned using

SAS Studio

Preferences:

• Time-out interval

• Do not use 1 hour

Page 29: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Random things I’ve learned using

SAS Studio

Preferences:

• You can turn off (or on)

autocomplete

Page 30: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Random things I’ve learned using

SAS Studio

You may not be able to see all of

your dataset!?

• Limited to 500 columns

Page 31: SAS Tips and Tricks Group... · 2017. 5. 18. · SAS Tips and Tricks April 2017 Doug Dover Senior Methodologist Epidemiology and Surveillance ... SAS Studio • It has two interfaces

Thank you.

Questions, comments, or thoughts?

Please contact me at

[email protected]