Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.

Similar presentations


Presentation on theme: "Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks."— Presentation transcript:

1 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Eliminating Redundant Custom Formats How to Really Take Advantage of PROC SQL, PROC CATALOG, and the DATA Step

2 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Eliminating Redundant Custom Formats Phase I: Generate Catalog of Unique Formats Phase II: Update Dataset Descriptor

3 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Eliminating Redundant Custom Formats  Phase I: Generate Catalog of Unique Formats  Phase II: Update Dataset Descriptor

4 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format 2.Optimize Length of Key Variable 3.Sort Keys Dataset and Generate Index for FMTNAME 4.Prepend VARNUM of Variables with Custom Formats 5.Generate View of Unique Format Keys 6.Generate Dataset of Unique Custom Format Metadata Records 7.Generate Persistent Unique Formats Catalog  Phase I: Generate Catalog of Unique Formats

5 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format 2.Optimize Length of Key Variable 3.Sort Keys Dataset and Generate Index for FMTNAME 4.Prepend VARNUM of Variables with Custom Formats 5.Generate View of Unique Format Keys 6.Generate Dataset of Unique Custom Format Metadata Records 7.Generate Persistent Unique Formats Catalog Phase I: Generate Catalog of Unique Formats

6 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Formats Crosswalk Dataset 2.Generate Crosswalk Pairs Dataset 3.Update Dataset Descriptor Phase II: Assign Unique Formats to Dataset Variables

7 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format 2.Optimize Length of Key Variable 3.Sort Keys Dataset and Generate Index for FMTNAME 4.Prepend VARNUM of Variables with Custom Formats 5.Generate View of Unique Format Keys 6.Generate Dataset of Unique Custom Format Metadata Records 7.Generate Persistent Unique Formats Catalog  Phase I: Generate Catalog of Unique Formats

8 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format proc format library = user cntlout = user._format_metadata ; quit ; a.Generate Formats Metadata Dataset from Existing Catalog

9 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format proc format library = user cntlout = work._format_metadata ; quit ; a.Generate Formats Metadata Dataset from Existing Catalog

10 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.

11 Variables in Creation Order #VariableTypeLenLabel 1FMTNAMEChar32Format name 2STARTChar16Starting value for format 3ENDChar16Ending value for format 4LABELChar31Format value label 5MINNum3Minimum length 6MAXNum3Maximum length 7DEFAULTNum3Default length 8LENGTHNum3Format length 9FUZZNum8Fuzz value 10PREFIXChar2Prefix characters Variables in Creation Order #VariableTypeLenLabel 11MULTNum8Multiplier 12FILLChar1Fill character 13NOEDITNum3Is picture string noedit? 14TYPEChar1Type of format 15SEXCLChar1Start exclusion 16EEXCLChar1End exclusion 17HLOChar11Additional information 18DECSEPChar1Decimal separator 19DIG3SEPChar1Three-digit separator 20DATATYPEChar8Date/time/datetime? 21LANGUAGEChar8Language for date strings _FORMAT_METADATA Contents

12 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Variables in Creation Order #VariableTypeLenLabel 1FMTNAMEChar32Format name 2STARTChar16Starting value for format 3ENDChar16Ending value for format 4LABELChar31Format value label 5MINNum3Minimum length 6MAXNum3Maximum length 7DEFAULTNum3Default length 8LENGTHNum3Format length 9FUZZNum8Fuzz value 10PREFIXChar2Prefix characters Variables in Creation Order #VariableTypeLenLabel 11MULTNum8Multiplier 12FILLChar1Fill character 13NOEDITNum3Is picture string noedit? 14TYPEChar1Type of format 15SEXCLChar1Start exclusion 16EEXCLChar1End exclusion 17HLOChar11Additional information 18DECSEPChar1Decimal separator 19DIG3SEPChar1Three-digit separator 20DATATYPEChar8Date/time/datetime? 21LANGUAGEChar8Language for date strings _FORMAT_METADATA Contents

13 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format data work._custom_format_keys ( keep = fmtname type custom_format_key key_length where = (!(missing(custom_format_key))) ) ; set USER._FORMAT_METADATA ( ) ; by fmtname ; a.Generate Formats Metadata Dataset from Existing Catalog b.Generate Custom Format Keys Dataset

14 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format attrib CUSTOM_FORMAT_KEY length = $ &_MAX_KEY_LEN format = $CHAR&_MAX_KEY_LEN.. label = 'Custom Format Key' KEY_LENGTH length = 8 format = comma12.0 label = 'Key Length' ; retain custom_format_key (' ') format_count (0) ; a.Generate Formats Metadata Dataset from Existing Catalog b.Generate Custom Format Keys Dataset

15 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format * CHECK FOR CARROT CHARACTER IN VALUES AND LABELS ; if ( (indexc(start,'^') NE 0) or (indexc(end,'^') NE 0) or (indexc(label,'^') NE 0) or (indexc(sexcl,'^') NE 0) or (indexc(eexcl,'^') NE 0) ) then put 'WARNING: CARROT CHARACTER USED: ' fmtname= start= end= label= sexcl= eexcl= ; a.Generate Formats Metadata Dataset from Existing Catalog b.Generate Custom Format Keys Dataset

16 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format * GENERATE THE CUSTOM FORMAT KEY ; custom_format_key = catx( '^', custom_format_key, start, end, label, type, sexcl, eexcl ) ; a.Generate Formats Metadata Dataset from Existing Catalog b.Generate Custom Format Keys Dataset

17 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Unique Format Keys for Each Custom Format if (last.fmtname) then do ; format_count ++ 1 ; key_length = length(trim(left(custom_format_key))) ; if (key_length GE %eval(&_MAX_KEY_LEN - 1)) then put 'WARNING: POTENTIAL KEY LENGTH OVERUN: ' FORMAT_COUNT= ; output ; custom_format_key = '' ; end ; run ; a.Generate Formats Metadata Dataset from Existing Catalog b.Generate Custom Format Keys Dataset

18 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. _CUSTOM_FORMAT_KEYS Contents Variables in Creation Order #VariableTypeLenLabel 1CUSTOM_FORMAT_KEYChar32767Custom Format Key 2KEY_LENGTHNum8Key Length 3FMTNAMEChar32Format name 4TYPEChar1Type of format

19 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset of Custom Format Keys FMTNAME CUSTOM_FORMAT_KEY STRING_LENGTH V20A 000.NONE130NNN111.ONEDAY130NNN222.TWODAYS130NNN333.THRE EDAYS130NNN444.FOURDAYS130NNN555.FIVEDAYS130NNN666.SIXD AYS130NNN777.EVERYDAY130NNN888.DON'TKNOW130NNN999.RF.NA 130NNN^9^9^9.RF.NA^13^0^N^N^N 194 V20B 000.NONE130NNN111.ONEDAY130NNN222.TWODAYS130NNN333.THRE EDAYS130NNN444.FOURDAYS130NNN555.FIVEDAYS130NNN666.SIXD AYS130NNN777.EVERYDAY130NNN888.DON'TKNOW130NNN999.RF.NA 130NNN^9^9^9.RF.NA^13^0^N^N^N 194 V20C 000.NONE130NNN111.ONEDAY130NNN222.TWODAYS130NNN333.THRE EDAYS130NNN444.FOURDAYS130NNN555.FIVEDAYS130NNN666.SIXD AYS130NNN777.EVERYDAY130NNN888.DON'TKNOW130NNN999.RF.NA 130NNN^9^9^9.RF.NA^13^0^N^N^N 194 V20D 000.NONE130NNN111.ONEDAY130NNN222.TWODAYS130NNN333.THRE EDAYS130NNN444.FOURDAYS130NNN555.FIVEDAYS130NNN666.SIXD AYS130NNN777.EVERYDAY130NNN888.DON'TKNOW130NNN999.RF.NA 130NNN^9^9^9.RF.NA^13^0^N^N^N 194 WEIGHT000.NoPostIW130NNN^0^0^0.NoPostIW^13^0^N^N^N44

20 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 2.Optimize Length of Key Variable * GENERATE AND EXPORT MAXIMUM KEY LENGTH TO MACRO VARIABLE ; proc sql noprint ; select strip(put(max(key_length),5.0)) into :_maximum_key_length from work._custom_format_keys ; quit ;

21 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 2.Optimize Length of Key Variable data WORK._CUSTOM_FORMAT_KEYS ( label = '_CUSTOM_FORMAT_KEYS' ) ; attrib fmtname label = 'Format Name' length = $ 32 type label = 'Variable Type' length = $ 1 custom_format_key label = 'Custom Format Key' length = $ &_MAXIMUM_KEY_LENGTH format = %nrbquote($CHAR%trim(&_MAXIMUM_KEY_LENGTH).) ; set WORK._CUSTOM_FORMAT_KEYS ( drop = key_length ) ; run ;

22 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 3.Sort Keys Dataset and Generate Index for FMTNAME proc sort data = work._custom_format_keys out = work._custom_format_keys ( index = (fmtname) ) ; by custom_format_key fmtname type ; run ;

23 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 4.Prepend VARNUM of Variables with Custom Formats proc sql ; create view work._ordered_custom_format_keys as select variables.varnum, keys.fmtname as fmtname, variables.type as type, keys.custom_format_key as custom_format_key from WORK._CUSTOM_FORMAT_KEYS keys left join USER._VARIABLE_METADATA variables on (cats(keys.fmtname,'.') EQ variables.format) and (keys.type EQ upcase(substr(variables.type,1,1)))

24 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 4.Prepend VARNUM of Variables with Custom Formats order by custom_format_key, varnum ; quit ;

25 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 5.Generate View of Unique Format Keys data work._unique_format_keys / view = work._unique_format_keys ; set work._ordered_custom_format_keys ; by custom_format_key ; if (first.custom_format_key) then output ; run ;

26 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset of Unique Format Records FMTNAMECUSTOM_FORMAT_STRINGSTRING_LENGTH V20A 000.NONE130NNN111.ONEDAY130NNN222.TWODAYS130NNN333.THRE EDAYS130NNN444.FOURDAYS130NNN555.FIVEDAYS130NNN666.SIXDA YS130NNN777.EVERYDAY130NNN888.DON'TKNOW130NNN999.RF.NA13 0NNN^9^9^9.RF.NA^13^0^N^N^N 194 WEIGHT000.NoPostIW130NNN^0^0^0.NoPostIW^13^0^N^N^N44 V22C 0000.NA160NNN andolder160NNN^97^97^97.97andolder^16^0^N ^N^N 67 V05C NNN NNN335060NNN NNN NNN99NA60NNN^9^9^NA^6^0^N^N^N 83 V00I NNN NNN335070NNN NNN NNN99NA70NNN^9^9^NA^7^0^N^N^N 83 V14G NNN NNN NNN NNN NNN6665&older100NNN99NA100NNN^9^9^NA^10^0^N^N^N 109 V01D 116-7days100NNN223-5days100NNN331- 2days100NNN440days100NNN99NA100NNN^9^9^NA^10^0^N^N^N 86 V02F 117days80NNN223-6days80NNN331- 2days80NNN440days80NNN99NA80NNN^9^9^NA^8^0^N^N^N 78 V09E11Addresssocialproblems230NNN77Vigorouslyenforcelaws230NNN99NA230 NNN^9^9^NA^23^0^N^N^N 86

27 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 6.Generate View of Unique Custom Format Metadata Records proc sql ; create view work._unique_format_view as select * from USER._FORMAT_METADATA where fmtname in ( select fmtname from WORK._UNIQUE_FORMAT_KEYS ) order by fmtname, type, start, end ;

28 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 7.Generate Persistent Unique Formats Catalog proc format library = USER cntlin = WORK._UNIQUE_FORMAT_VIEW ; quit ;

29 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Eliminating Redundant Custom Formats  Phase I: Generate Catalog of Unique Formats  Phase II: Update Dataset Descriptor

30 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Formats Crosswalk Dataset 2.Generate Crosswalk Pairs Dataset 3.Update Dataset Descriptor  Phase II: Update Dataset Descriptor

31 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Formats Crosswalk Dataset 2.Generate Crosswalk Pairs Dataset 3.Update Dataset Descriptor  Phase II: Update Dataset Descriptor

32 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Formats Crosswalk Dataset 2.Generate Crosswalk Pairs Dataset 3.Update Dataset Descriptor  Phase II: Update Dataset Descriptor

33 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 1.Generate Formats Crosswalk Dataset proc sql ; create table WORK._FORMAT_CROSSWALK as select distinct _custom_format_keys.fmtname as fmtname, _custom_format_keys.type as type, _unique_format_keys.fmtname as unique_fmtname from work._custom_format_keys custom left join work._unique_format_keys unique on (custom.custom_format_key EQ unique.custom_format_key) ; quit ;

34 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 2.Generate Crosswalk Pairs Dataset proc sql ; create table _NUMBERED_CROSSWALK_PAIRS as select variables.varnum, variables.name, variables.type, crosswalk.unique_fmtname from _FORMATTED_VARIABLE_METADATA variables left join _FORMAT_CROSSWALK crosswalk on (compress(variables.format,'$.') EQ crosswalk.fmtname) and (upcase(substr(variables.type,1,1)) EQ crosswalk.type) order by varnum ;

35 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 3.Update Dataset Descriptor data _NULL_ ; set _NUMBERED_CROSSWALK_PAIRS end = end_of_dataset ; call symput( '_varname_' || strip(put(_N_,6.0)), strip(name) ) ; if type EQ 'char' then call symput( '_fmtname_' || strip(put(_N_,6.0)), strip(cats('$',unique_fmtname,'.')) ) ; else call symput( '_fmtname_' || strip(put(_N_,6.0)), strip(cats(unique_fmtname,'.')) ) ; if end_of_dataset then call symput( '_pairs_n', strip(put(_N_,6.0)) ) ;

36 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 3.Update Dataset Descriptor * UPDATE DATASET VARIABLE--FORMAT SPECIFICATIONS. ; proc datasets library = &_LIBNAME nolist ; %put NOTE: CLEARING OLD VARIABLE--FORMAT PAIRINGS. ; modify &_DS_NAME ; format _ALL_ ; run ;

37 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. 3.Update Dataset Descriptor modify &_DS_NAME ; ; format %do _i = 1 %to &_PAIRS_N ; &&_VARNAME_&_I &&_FMTNAME_&_I %end ; ; run ; quit ;

38 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Author contact information second line Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Eliminating Redundant Custom Formats (or How to Really Take Advantage of PROC SQL, PROC CATALOG, and the DATA Step) Philip A. Wright Inter-university Consortium for Political and Social Research (ICPSR), The Institute for Social Research (ISR), University of Michigan P.O. Box 1248 Ann Arbor, Michigan Philip A. Wright Inter-university Consortium for Political and Social Research (ICPSR), The Institute for Social Research (ISR), University of Michigan P.O. Box 1248 Ann Arbor, Michigan

39 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Table of Formats Metadata WORK._VARIABLE_FORMATS #VariableTypeLenFormatLabel 1varnameChar32$32.Variable Name 2formatChar49$49.Variable Format

40 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Table of Dataset Variable Metadata create table work._contents as select columns.name label = 'Variable Name', columns.type label = 'Variable Type', columns.length label = 'Variable Length', columns.varnum label = 'Variable Number', columns.label label = 'Variable Label', upcase(formats.format) as format label = Variable Format' length=49 from dictionary.columns

41 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Table of Dataset Variable Metadata from dictionary.columns left join work._variable_formats formats on (columns.name EQ formats.varname ) where (libname EQ 'USER') and (memtype EQ 'DATA') and (memname EQ 'MEMNAME') order by varnum ;

42 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Table of Dataset Variable Metadata WORK._CONTENTS #VariableTypeLenLabel 1nameChar32Variable Name 2typeChar4Variable Type 3lengthNum8Variable Length 4varnumNum8Variable Number 5labelChar256Variable Label 6formatChar49Variable Format

43 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset from Formats Catalog proc format library = work cntlout = work.formats_info ( replace = yes ) fmtlib noprint ; run ;

44 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Integrity Constraint for FORMATS_INFO Dataset proc datasets library = work nolist ; modify formats_info ; ic create pk = primary key ( fmtname start end ) ; quit ;

45 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Table of Variables with Custom Formats proc sql ; create table work._custom_formatted_variables as select distinct contents.varnum, contents.name as varname, formats.fmtname, formats.length from work._formats_info formats left join work._contents contents on (formats.fmtname EQ contents.format) where

46 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Table of Variables with Custom Formats where (varname is not null) and (fmtname is not null) order by varnum ; quit ;

47 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Table of Variables with Custom Formats WORK.FORMATS_INFO #VariableLabel 1FMTNAMEFormat name 2START Starting value for format 3END Ending value for format 4LABELFormat value label 5MINMinimum length 6MAXMaximum length 22 CUSTOM_FORMAT _STRING Custom Format String 23STRING_LENGTHString Length Variables in Creation Order #VariableTypeLenLabel 1nameChar32Variable Name 2typeChar4Variable Type 3lengthNum8Variable Length 4varnumNum8Variable Number 5labelChar256Variable Label 6formatChar49Variable Format 1 1..

48 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Table of Variables with Custom Formats WORK._CUSTOM_FORMATTED VARIABLES #VariableTypeLenLabel 1VARNUMNum8Variable Number 2VARNAMEChar32Variable Name 3FMTNAMEChar32Format name 4LENGTHNum3Format length

49 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. data work.custom_format_keys ( keep = fmtname custom_format_string string_length where = (not(missing(custom_format_string))) ) ; set work.formats_info ( ) ; by fmtname ; Generate Dataset of Custom Format Keys

50 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. retain custom_format_string (' ') format_count (0) ; custom_format_string = compress(custom_format_string) || '^' || compress(start) || '^' || compress(end) || '^' || compress(label) || '^' || compress(put(length, 8.0)) || '^' || compress(put(noedit, 1.0)) || '^' || compress(type) || '^' || compress(sexcl) || '^' || compress(eexcl) ; Generate Dataset of Custom Format Keys

51 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. if (last.fmtname) then do ; format_count ++ 1 ; string_length = length(trim(left(custom_format_string))) ; if (string_length GE %eval(&MAX_STRING_LEN - 1)) then put 'WARNING: POTENTIAL STRING LENGTH OVERUN: ' FORMAT_COUNT= ; output ; custom_format_string = ' ' ; end ; run ; Generate Dataset of Custom Format Keys

52 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset of Custom Format Keys WORK._CUSTOM _FORMAT_STRINGS #VariableTypeLenFormatLabel 1FMTNAMEChar32Format name 2CUSTOM_FORMAT_KEYChar8184$CHAR1024.Custom Format Key 3STRING_LENGTHNum8COMMA12.String Length 4COUNTNum8Frequency Count

53 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset of Custom Format Keys FMTNAMECUSTOM_FORMAT_STRINGSTRING_LENGTH V22C 0000.NA160NNN andolder160NNN^97^97^97.97andolder^16^0^ N^N^N 67 V05C NNN NNN335060NNN NNN NNN99NA60NNN^9^9^NA^6^0^N^N^N 83 V05E NNN NNN335060NNN NNN NNN99NA60NNN^9^9^NA^6^0^N^N^N 83 V05F NNN NNN335060NNN NNN NNN99NA60NNN^9^9^NA^6^0^N^N^N 83 V05G NNN NNN335060NNN NNN NNN99NA60NNN^9^9^NA^6^0^N^N^N 83 V00I NNN NNN335070NNN NNN NNN99NA70NNN^9^9^NA^7^0^N^N^N 83 V01A NNN NNN335070NNN NNN NNN99NA70NNN^9^9^NA^7^0^N^N^N 83 V03J NNN NNN335070NNN NNN NNN99NA70NNN^9^9^NA^7^0^N^N^N 83

54 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Sort Custom Format Keys by Key proc sort data = work._custom_format_keys out = work._custom_format_keys ( index = (fmtname) ) ; by custom_format_key ; run ;

55 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Custom Format Key Frequencies Dataset proc freq data = work._custom_format_keys noprint ; tables custom_format_key / nocol nocum nopercent norow out = work._format_string_frequencies ( drop = percent ) ; proc sort data = work._format_string_frequencies ; by custom_format_key ; run ;

56 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Augment Custom Format Keys with Variable Info proc sql ; alter table work._custom_format_keys add varname char(32) label='Variable Name' format=$32., varnum num(8) label='Variable Number' ; update work._custom_format_keys keys

57 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Augment Custom Format Keys with Variable Info set varname = ( select distinct name from work._contents contents where contents.format EQ keys.fmtname ), varnum = ( select distinct varnum from work._contents contents where contents.format EQ keys.fmtname ) ; run ;

58 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset of Unique Format Records proc sort data=work._custom_format_keys force ; by custom_format_key varname ;

59 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset of Unique Format Records data work._unique_format_records ; set work._custom_format_keys ; by custom_format_key ; if (first.custom_format_key) then output ; run ;

60 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset Comprised of Unique Formats Info proc sql ; create table work._unique_formats_info as select unique.varnum, unique.fmtname, formats.start, formats.end, formats.label, formats.type, formats.eexcl, formats.sexcl from

61 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset Comprised of Unique Formats Info from work._unique_format_records unique left join work._formats_info formats on ( unique.fmtname EQ formats.fmtname ) order by varnum, fmtname, start, end ; quit ;

62 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Catalog Comprised of Unique Formats options nonotes ; proc catalog catalog = work.formats kill ; quit ; options notes ; proc format library = work cntlin = work._unique_formats_info (drop = varnum) ; ; quit ;

63 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset with New Variable-Format Pairings options ibufsize=32767 ; * optimizes processing ; proc sql ; alter table work._custom_format_keys add new_format char(49) label = 'New Format' format=$49., type char(4) label = 'Variable Type' format=$4. ;

64 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset with New Variable-Format Pairings update work._custom_format_keys keys set new_format = ( select fmtname from work._unique_format_records records where records.custom_format_key EQ keys.custom_format_key ), type = ( select type from work._contents contents where contents.name EQ keys.varname ) ;

65 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset with New Variable-Format Pairings proc sort data = work._custom_format_keys ; by new_format varnum ; run ;

66 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset with New Variable-Format Pairings proc sql ; create table work._new_variable_format_pairs as select distinct varnum, varname, type, new_format from work._custom_format_keys order by varnum ; quit ;

67 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Export Variable-Format Pairs to Indexed Macro Variables data _null_ ; set work._new_variable_format_pairs end = last_observation ; if (type EQ 'num') then new_format = strip(new_format) || '.' ; else new_format = '$’||strip(new_format) || '.' ; call symput('_varname_’||strip(put(_N_,4.0)), strip(varname)); call symput('_format_'||strip(put(_N_,4.0)), strip(new_format)); if (last_observation) then call symput('_pairs_n', strip(put(_N_,4.0))) ; run ;

68 Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Generate Dataset with New Variable-Format Designations proc datasets library = work nolist ; modify memname ; format %do _i = 1 %to &_PAIRS_N ; &&_VARNAME_&_I &&_FORMAT_&_I %end ; ; quit ;


Download ppt "Copyright © 2010, SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks."

Similar presentations


Ads by Google