sas_adv_preguide_notes_by_cathyz77 (2016.07.08)--我没看.pdf

Sas_adv_preguide_notes_by_cathyz77 (2016.07.08)--我没看.pdf

This preview shows page 1 out of 26 pages.

Unformatted text preview: CHAPTER 24 Querying Data Efficiency CHAPTER 24 Querying Data Efficiency 1, Using an Index for Efficient WHERE Processing index index code index subset data sort CPU, I/O value index uniqueness loading index page memory index 2,Identifying Available Indexes WHERE sas index 3,Identifying Conditions That Can Be Optimized WHERE operator functions operator IN / NOT IN / : / CONTAINS / LIKE / IS NULL / IS MISSING function TRIM / SUBTRI element TRIM SUBTRI function WEEKDAY SUNSTRI sound like operator =* operaton 4, Estimating the Number of Observations observation index 5,Comparing Probable Resource Usage index subset data file page data order file I/O operations index data set subset 3 data file I/O sas data set 6,Deciding Whether to Create an Index 7,Comparing Procedures That Produce Detail Reports PROC PRINT: PROC SQL: data listing data report cathyz77 footnotes column sum column row statistics 8, Comparing Tools for Summarizing Data output control PROC PRINT data set PROC MEANS (or PROC SUMMARY) data set PROC SQL PROC SORT _TYPE_ PROC MEANS NWAY; b output PROC REPORT class combination PROC TABULATE statistics CHAPTER 23 Selecting Efficient Sorting Strategies Map 1, Avoiding Unnecessary Sorts BY data SORT indexed index variable data by variable index BY variable NOTSORTED; FIRST. LAST. BY variable GROUPFORMAT; data step format data CLASS variable BY efficient CPU time memory SORTEDBY = by-clause </collate-name> | _NULL_ data sort sas data I/O mean summary sort 2, Using a Threaded Sort PROC SORT sas-data-set-name THREADS | NOTHREADS CPUCOUNT = n | ACTUAL thread sort subset sort processors 3, Calculating and Allocating Sort Resources bytes required = (key-variable-length + observation-length) *number-of-observations* 4 workspace SORTSIZE = memory-specifications sort MAX ( memory) n (memory in bytes) nK(memory in kilobytes) nM(megabytes) nG(gigabytes) 4, Handling Large Data Sets data set sort combine PROC SORT DATA = data-set-name TAGSORT; BY tags input data set sort data observation numbers tag file 5, Removing Duplicate Observations Efficiently PROC SORT DATA = data-set-name NODUPKEY; j value PROC SORT DATA = data-set-name NODUPRECS; EQUALS | NOEQUALS EQUALS output data set input memory order BY observation value NOEQUALS BY order value data CPU CHAPTER 22 Utilizing Best Practices Map 1, Executing Only Necessary Statements IF SELECT data set IF statement resource DO data subset resource 2, Eliminating Unnecessary Passes through the Data DATA step SORT WHERE DATASETS output data set sorted subsets 3, Reading and Writing Only Essential Data observation WHERE IF WHERE OBS,FIRSTOBS KEEP DROP 4, Storing Data in SAS Data Sets procedure report SQL DATASETS FREQ TABULATE 5, Avoiding Unnecessary Procedure Invocation CHAPTER 21 Controlling Data Storage Space Map 1, Reducing Data Storage Space for Character Variables sas avlue LENGTH variable $ length; length length sas 8 bytes 2, Reducing Data Storage Space for Numeric Variables bit bit exponent LENGTH statement length length limitation length length data set 56 bits mantissa value length PROC COMPARE BASE = sas-data-set-1 COMPARE = sad-data-set-2 RUN cathyz77 3, Compressing Data Files 16byte data set page observation value observation 1bit observation value value page file observation type 12 24bytes overhead flags pointers file value value OPTIONS COMPRESS = NO | YES | CHAR | BINARY; POINTOBS = YES | NO; data set direct access OPTION REUSE = NO | YES; data space 0 page 0 page 28bytes missing option data space 4, Using SAS DATA Step Views to Conserve Data Storage Space sas data view data information data value instruction data value DATA step view DATA step view always access data source combine data DATA SAS-data-view <SAS-data-file-1 ... SAS data-file-n> / copy VIEW=SAS-data-view; <SAS statements> RUN; CHAPTER 20 Controlling Memory Usage Map 1, Controlling Page Size and the Number of Buffers I/O input output sas Page size page BUFSIZE = MIN | MAX | n; BUFNO = MIN | MAX | n; data buffer memory memory page size buffer data page size page page size 2, Using the SASFILE Statement SASFILE sas-data-file <passwork-option> OPEN | LOAD | CLOSE; sas file memory program sas file pages buffer file size buffer buffer memory CHAPTER 19 Introduction to Efficient SAS Programming Map 1, Overview of Computing Resources resource programmer time CPU time real time memory 2, Assessing Efficiency Needs at Your Site sas program size run data data volume type data storage space I/O 3, Understanding Efficiency Trade-offs CPUtime I/O memory real time CPU time program programmer time 4, Using SAS System Options to Track Resources NOSTIMER (track CPU time), NOMEMRPT (track memory usage), NOFULLSTIMER (track ( track statistics) resource), NOSTATS 5, Using Benchmarks to Compare Techniques CHAPTER 18 Modifying SAS Data Sets and Tracking Changes Map 1, Using the MODIFY Statement MODIFY data set sas DATA SET SET data set sas copy copy 2, Modifying All Observations in a SAS Data Set data set observation DATA SAS-data-set; MODIFY SAS-data-set; existing-variable = expression; RUN; 3, Modifying Observations Using a Transaction Data Set observation DATA SAS-data-set; transaction data set MODIFY SAS-data-set transaction-data-set; BY key-variable; RUN; master data set observation by transaction missing sas master NOMISSINGCHECK value UPDATEMODE= missing 4, Modifying Observations Located by an Index MODIFY SAS-data-set KEY=index-name / UNIQUE; index update value transection data set observation master data set master transection data set observation match value index update UNIQUE value observation sas transaction 5, Controlling the Update Process OUTPUT; REPLACE; REMOVE; option sas observation data set OUTPUT observation data set data set statement sas REPLACE observation same location REMOVE observation master data set IF _IORC_ %SYSRC (mnemonic) THEN... _DSENMR: tran observation master _DSEMTR tran observation master _DSENOM: match observation _SOK: observation sok = 0 6, Understanding Integrity Constraints 7, Placing Integrity Constraints on a Data Set PROC DATASETS LIB=libref <NOLIST>; MODIFY SAS-data-set; IC CREATE constraint-name=constraint <MESSAGE=‘Error Message’>; QUIT; DATA MODIFY PROC WQL ~ INSERT INTO,SET,UPDATE PROC APPEND interactive data editing window 8, Documenting Integrity Constraints PROC DATASETS LIB=libref <NOLIST>; CONTENTS DATA=SAS-data-set; QUIT; 9, Removing Integrity Constraints PROC DATASETS LIB=libref <NOLIST>; MODIFY SAS-data-set; IC DELETE constraint-name; QUIT; 10, Understanding Audit Trails audit trails optional sas file sas table data set 11, Initiating and Reading Audit Trails PROC DATASETS LIB=libref <NOLIST>; AUDIT SAS-data-set <SAS-password>; INITIATE; RUN; QUIT; (TYPE=AUDIT) 12, Controlling Data in the Audit Trail data set variable audit trail data set audit trail variable AT opcode atopcode observation date time userid obsno retrurncode audit file code message user variable file USER_VAR variable-name<$><length><LABEL=‘variable-label’>; LOG <audit-settings> audit settings BEFORE_IMAGE=YES|NO update images DATA_IMAGE = YES|NO update images ERROR_IMAGE=YES|NO update images 13, Controlling the Audit Trail PROC DATASETS LIB=libref<NOLIST>; AUDIT SAS-data-set <SAS-password>; SUSPEND | RESUME | TERMINATE; QUIT; suspend: resume terminate event 14 Understanding Generation Data Sets sas library data set generation data set generation group root member name version number generations sas filename 28 version number data set version generation base version 15, Initiating Generation Data Sets PROC DATASETS LIB=libref <NOLIST>; MODIFY SAS-data-set (GENMAX=n); QUIT; 16, Processing Generation Data Sets GENNUM = n n absolute reference to history version by generation number n version current version relative reference to historical CHAPTER 17 Formatting data Map 1, Creating Custom Formats Using the VALUE Statement VALUEformat-name(MULTILABEL); /MLF format format value group 2, Creating Custom Formats Using the PICTURE Statement PROC FORMAT; PICTUREformat-name value-or-range=‘picture’; RUN; print picture digit selectors 0-9 value-or-range='00/99’ message characters digit selector directive date time datetime date-value-type) l % cathyz77 value value-or-range=’99 JAN’; value-or-range, ‘picture’(DATATYPE=sasdirective 3, Managing Custom Formats PROC FORMAT LIB=library FMTLIB; SELECT format-name; EXCLUDE format-name; RUN; PROC FORMAT FMTLB format description PROC CATALOG CATALOG=libref.catalog; CONTENTS<OUT=SAS-data-set>; COPY OUT=libref.catalog<options>; SELECTentry-name.entry-type(s); EXCLUDEentry-name.entry-type(s); DELETEentry-name.entry-type(s); RUN; QUIT; 4, Using Custom Formats format PROC DATASETS LIB=SAS-library <NOLIST>; MODIFY SAS-data-set; FORMAT variable(s) format; QUIT; sas Work.Formats Library.Formats format OPTIONS FMTSEARCH= (catalog-1 catalog-2...catalog-n); OPTIONS FMTERR | NOFMTERR sas missing format format format 5, Creating Formats from SAS Data Sets sas data set format value information PROC FORMAT LIBRARY=libref.catalog control data set CNTLIN=SAS-data-set; FmtName( $ format ) 6, Creating SAS Data Sets from Custom Fomats format data set PROC FORMAT LIBRARY=libref.catalog CNTLOUT=SAS-data-set; SELECTformat-name format-name...; EXCLUDEformat-name format-name...; sort), Start, Label, End( range), Type( RUN; CHAPTER 16 Using Lookup Tables to Match Data Map 1, Using Multidimensional Arrays ARRAY array-name {rows, column, …} <$> <length> <array-elements><(initial values)>; 2, Using Stored Array Values case 3, Using PROC TRANSPOSE PROC TRANSPOSE<DATA=input-data-set> <OUT=output-data-set> <NAME=variable-name> <PREFIX=variable-name>; BY<DESCENDING>variable-1<...<DESCENDING>variable-n> <NOTSORTED>; VARvariable(s); RUN; output _NAME_ _NAME_,COL1,COL2, ... observation value source 4, Merging the Transposed Data Set case 5, Using Hash Objects as Lookup Tables value observation DATA step datas sort indexed hash object table key data hash object DECLAREobject variable<(<argument_tag-1: value-1<, ...argument_tag-n:value-n>>)>; object value hash hater( KEY ) instantiating hash object variable =_NEW_object(<argument_tag-1: value-1<, ...argument_tag-n:value-n>>); instantiate DECLARE object variable(); key data object.method(<argument_tag-1: value-1<, ...argument_tag-n: value-n>>); method definekey, definedata, add, find hash object key value key data sas CALL MISSING ( ) CHAPTER 15 Combining Data Horizontally Map 1, Reviewing Terminology 2, Working with Lookup Values Outside of SAS Data Sets IF THEN ARRAY format 3, Combining Data with the DATA Step Match-Merge merge 4, Using PROC SQL to Join Data SQL 32 table 5, Comparing DATA Step Match-Merges and PROC SQL Joins DATA step merge merge sort data set BY arrays DO loops BY value SQL Join sort join32 index data set data set tables views resource reports 6, Combining Summary Data and Detail Data basic 7, Using an Index to Combine Data SET sas-data-set KEY = index-name matching KEY option sas sas _IORC_ 0 sas matching observation 8, Using a Transactional Data Set data set update DATA master-data-set; data set data set observation value UPDATE master-data-set transaction-data-set; BY by-variables; RUN; CHAPTER 14 Combining Data Vertically Map 1, Using a FILENAME Statement FILENAME fileref (‘external-file1’ ‘external-file2’ … ‘external-filen’); 2, Using an INFILE Statement INFILE file-specification FILEVAR = variable; input file file-specification input file variable hold filename sas sas log COMPRESS (source, <characters-to-remove>) INFILE file-specification END = variable; sas record variable 0 1 record INTNX observation END sas 1 TODAY MONTH 3, Appending SAS Data Sets PROC APPEND BASE = sas-data-set DATA = sas-data-set; RUN; SAS DATA= missing data set log BASE = data set BASE PROC APPEND BASE = sas-data-set DATA = sad-data-set <FORCE>; BASE DATA force BASE DATA missing CHAPTER 13 Creating Samples and Indexes Map 1, Creating a Systematic Sample from a Known Number of Observations systematic sample: data set SET data-set-name POINT = point variable observation point sas observation DO LOOP sample STOP statement observation 2, Creating a Systematic Sample from a Unknown Number of Observations SET sas-data-set NOBS = variable ; execution 3, Creating a Random Sample with Replacement RANUNI (seed) seed generate seed DATA step 0 1 seed 0 multiplier CEIL (argument) CEIL (RANUNI (seed)) argument 4, Creating a Random Sample without Replacement DO WHILE loop 5, Using Indexes index sas simple index: composite index: observation key variable key variable value value 6, Creating Indexes in the DATA Step DATA sad-data-file-name (INDEX = (index-specification-1 </UNIQUE><…index-specification-n></UNIQUE>)); index key variable specification index (index-name = (variable-1 … variable-n)). UNIQUE key variable observation OPTIONS MSGLEVEL = N | I; log index index DATA step IF WHERE sas 7, Managing Indexes with PROC DATASETS PROC DATASETS LIBRARY = libber <NOLIST>; MODIFY sad-data-set-name; INDEX DELETE index-name; INDEX CREATE index-specification; QUIT; 8, Managing Indexes with PROC SQL PROC SQL; CREATE <UNIQUE> INDEX index-name ON table-name (column-1,… column-n); DROP INDEX index-name FROM table-name; QUIT; 9, Documenting and Maintaining Indexes index data set descriptor portion host dependent CONTENTS attribute list constraint list index attribute list copy index PROC DATASETS LIBRARY = old-libref <NOLIST>; COPY OUT = new libref; SELECT sad-data-set-name; QUIT; PROC COPY OUT = new-libref IN = old-libref <MOVE>; SELECT sas-data-set-name; RUN; QUIT; index PROC DATASETS LIBRARY = old-libref <NOLIST>; CHANGE old-data-set-name = new-data-set-name; QUIT; PROC DATASETS LIBRARY = libber <NOLIST>; MODIFY sad-data-set-name; RENAME old-data-set-name = new-data-set-name; QUIT; CHAPTER 12 Storing Macro Programs Map 1, Understanding Session-Compiled Macros compile macro sas catalog 2, Storing Macro Definitions in External Files %INCLUDE file-specification </SOURCE2>; 3, Storing Macro Definitions in Catalog SOURCE Entries sas catalog SOURCE entry catalog content PROC CATALOG CATALOG=libref.catalog; CONTENTS; QUIT; insert macro definition FILENAME fileref CATALOG ‘libber.catalog.entry-name.entry-type’; %INCLUDE fileref(entry-1); %INCLUDE fileref(entry-2); WORK. .macro .Macro sas session cathyz77 4, Using the Autocall Facility macro autocall library OPTIONS MAUTOSOURCE | NOMAUTOSOURCE; OPTIONS SASAUTOS = ( library-1, … library-n) ; autocall libraries autocall facility autocall facility auto call macros 5, Using Stored Compiled Macros OPTIONS MSTORED | NOMSTORED; stored complied macro facility OPTIONS SASMSTORE = libref complied macros %MACRO macro-name <(parameter list)> / SOTRE <DES = ‘description’>; text %MEND <macro-name>; MSTORED SASMSTORE call macro %MACRO macro-name <(parameter list)> / SOTRE SOURCE; %COPY macro-name / SOURCE <other options> CHAPTER 11 Creating and Using Macro Programs Map 1, Basic Concepts macro %MACRO macro-name text %MEND <macro-name>; macro compiling OPTIONS MCOMPILENOTE =NONE | NOAUTOCALL | ALL; MACRO compiling log macro macro macro % macro DATALINE 2, Developing and Debugging Macros OPTIONS MPRINT | NOPRINT; macro log OPTIONS MLOGIC | NOMLOGIC; macro macro actions %*comment macro comments 3, Using Macro Parameters parameter list macro positional parameter macro definition positional parameter %MACRO macro-name (parameter-1, … parametern); call macro text %MEND <macro-name>; keyword parameter definition macro value list value %MACRO macro-name (parameter-1=value-1, … parametern=value-n); call text %MEND <macro-name>; mixed parameter list positional keyword parameter positional keyword PARMBUFF OPTION parameter macro PARAMBUFF %MACRO macro-name / PARMBUFF text %MEND <macro-name>; parameter 4, Understanding Symbol Tables global symbol table sas session macro %LET statement DATA step SYMPUT DATA step SYMPUTX SQL SELECT INTO % GLOBAL statement %GLOBAL macro-variable-1 <… macro-variable-n>; local symbol table macro call macro macro %LET statement DATA step SYMPUT DATA step SYMPUTX SQL SELECT INTO parameters in macro definition % LOCAL statement macro definition %LOCAL macro-variable-1 <… macro-variable-n>; macro macro processor local table global table local table value %LET &variable-name global table multiple local symbol table macro program macro program OPTIONS MPRINTNEST | NOMPRINTNEST OPTIONS MLOGICNEST | NOMLOGICNEST sas macro nesting sas macro nesting local symbol table log MPRINT output log MLOGIC output 5, Processing Statements Conditionally %IF expression %THEN text; <%ELSE text;> IF THEN refer DATA step %IF expression %THEN %DO; text and/or macro language statement text %END; %ELSE %DO; text and/or macro language statement %END; %IF case sensitive cathyz77 6, Processing Statements Iteratively %DO index-variable = start %TO stop <BY increment>; text %END; 7, Using Arithmetic and Logical Expressions input stack %EVAL (arithmetic or logical expression); %SYSEVALF (expression <, conversion-type>); BEST32. format missing CHAPTER 10 Processing Macro Variables at Execution Time Map 1, Creating a Macro Variable During DATA Step Execution CALL SYMPUT ('macro-variable', ‘text'); macro DATA step text data-step-variable CALL SYMPUTX ('macro-variable', expression); macro PUT (sourse, format.) BEST12. 2, Creating Multiple Macro Variables During DATA Step Execution CALL SYMPUT (expression1, expression2); DATA step macro update 3, Referencing Macro Variables Indirectly Forward Re-Scan Rule &% token macro processor re-scan macro processor token indirect reference &&& && 4, Obtaining Macro Variable Values During DATA Step Execution SYMGET (macro-variable) DATA step macro value 5, Creating Macro Variables During PROC SQL Step Execution PROC SQL NOPRINT; SELECT column1, … column-n INTO :macro-variable-1, … macro-variable-n FROM table-1 | view-1 <WHERE expression> <other clauses>; QUIT; PROC SQL NOPRINT; SELECT column1 INTO :macro-variable-1 SEPARATED BY ‘delimiter 1' FROM table-1 | view-1 <WHERE expression> <other clauses>; QUIT; macro hold 6, Working with PROC SQL Views SYMGET &text data set value & re-scan reference trigger input 7, Using Macro Variables in SCL Programs CALL SYSPUT ('macro-variable', value); SCL program macro SCL-variable = SYMGETN (’macro-variable’) SCL program macro value CHAPTER 9 Introducing Macro Variables Map 1, Basic Concepts sas data set symbol table sas DATELINES statement reference global symbol table 2, Using Automatic Macro Variables SYSDATE,SYSDATE9,SYSDAY,SYSTIME YSLAST, SYSPARM, SYSERR 3, Using User-Defined Macro Variables %LET variable=value; value value 4, Processing Macro Variables program input stark complier sas step boundary literal token number token name token special token macro processor input stack sas program statement complier macro trigger tokens RUN, DATA, PROC code macro processor 5, Displaying Macro Variable Values in the SAS Log OPTIONS NOSYMBOLGEN | SYMBOLGEN option macro processor value %PUT text value log log _ALL_ ,_AUTOMATIC_, _USER_ 6, Using Macro Functions to Mask Special Characters value input stack compiler macro definition %STR (argument) tokens macro processor macro text compilation %NRSTR (argument) %STR & % %BQUOTE (argument) %NRBQUOTE (argument) %STR execution macro 7, Using Macro Functions to Manipulate Character Strings %UPCASE (argument) %QUPCASE(argument) argument macro trigger %SUBSTR (argument, position <,n>): %QSUBSTR (argument, position <,n>): argument macro trigger %INDEX (source string): text %SCAN (argument, n <,delimiters>):c macro %QSCAN (ar...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern