1 / 13

SAS v9, Enhancements

SAS v9, Enhancements. Prepared by: Luigi Muro – Consultant Bell Canada. Formats/Informats. Enhancements to the FORMAT Procedure. FORMAT and INFORMATS with longer names. 32 Characters for Numeric formats . 31 Characters for Character formats (allows for a $ sign).

meena
Télécharger la présentation

SAS v9, Enhancements

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SAS v9, Enhancements Prepared by: Luigi Muro – Consultant Bell Canada

  2. Formats/Informats Enhancements to the FORMAT Procedure • FORMAT and INFORMATS with longer names. • 32 Characters for Numeric formats. • 31 Characters for Character formats (allows for a $ sign). • Note: Not compatible with version 8 proc format; value $genderformat "1"="Female" "2"="Male"; NOTE: Format $GENDERFORMAT has been output.

  3. Character Functions New Character SAS Functions STRIP Strips leading and trailing blanks from a string CAT Concatenates character strings without removing leading or trailing blanks CATS Concatenates character strings and removes leading and trailing blanks CATT Concatenates character strings and removes trailing blanks CATX Concatenates strings, removes leading and trailing blanks, and inserts separators PROPCASE Converts all words in an argument to proper case CHAR Extracts a single character from a string FIRST Extracts the first character from a string

  4. Character Functions Concatenating Strings Have you ever used || (concat), TRIM, LEFT, and PUT functions. Version 8 and below: combine = trim(left(Char1)) || ‘ ‘ || left(Char2); remblanks = trim(left(put(1350.624, 8.2))); Version 9 (Reduce code complexity) combine = catx(‘ ‘, Char1, Char2); remblanks = strip(put(1350.624, 8.2));

  5. Macro Functions CREATING MACRO VARIABLES Commonly include LEFT, TRIM and PUT functions to make sure that the macro variable value is constructed properly. Version 8 and below: call symput(‘Max’, trim(left(put(maxValue , 8.))) ); Version 9 CALL SYMPUTX handles left justification, trimming, and character conversion. call symputx( ‘Max’ , maxValue);

  6. Character Functions The PROPCASE Function The PROPCASE function returns a string in proper (mixed) case. Example: line = 'macro-generated line'; line1 = PROPCASE(line, ' '); line2 = PROPCASE(line, ' -'); Result: line1 = Macro-generated Line line2 = Macro-Generated Line

  7. Data step – IN operator Integer ranges can be specified with an IN operator Version 8 and below: A. if code in (3,7,8,9,10,11,15,19,20,21,22,23,24,25) then put ‘Found’; B. if code = 3 or (code >= 7 and code <= 11) or code = 15 or (code >= 19 and code <= 25) ...; C. if code = 3 or (7 <= code <= 11) or code = 15 or (19 <= code <= 25) ...; Version 9 (Reduce code complexity) if code in (3, 7:11, 15, 19:25) then put ‘Found’;

  8. Data step - Putlog PUTLOG - Writes a message to the SAS log Data _null_ ; file print ; put 'This goes to OUTPUT window' ; putlog ‘This message goes to the LOG' ; putlog 'WARNING: ...' ; Line displayed as Green in log window putlog 'ERROR: ...‘ ; Line displayed as Red in log window put 'This goes to OUTPUT window' ; run ; Difference between Put and Putlog: PUTLOG explicitly writes to the SAS LOG. This means that you can direct regular PUT statements to another destination, and write to the log using PUTLOG without the need to redirect output to the LOG with a FILE LOG statement.

  9. Character Functions Extract a single character from a string using CHAR and FIRST Version 8 and Below: Data extract; MarketingCode='FD12Q1320'; Region=substr(MarketingCode, 5, 1); Product=substr(MarketingCode, 1, 1); run; Version 9: Data extract; MarketingCode='FD12Q1320'; Region=CHAR(MarketingCode, 5); Product=FIRST(MarketingCode); Run;

  10. PRX Perl regular expression (PRX) - Primary functions: PRXPARSE: To define a Perl regular expression to be used later by the other regular expression functions. Combination of alphanumeric characters, strings and metacharacters. PRXMATCH: Locate the position in a string, where a regular expression match is found. This function returns the first position in a string. If this pattern is not found, the function returns a zero. Other functions and call routines include: PRXSUBSTR, PRXPOSN, PRXNEXT, PRXPAREN DATA _NULL_; IF _N_ = 1 THEN PATTERN_NUM = PRXPARSE("/cat/"); RETAIN PATTERN_NUM; INPUT STRING $30.; POSITION = PRXMATCH(PATTERN_NUM,STRING); DATALINES; ... ;

  11. PRX Perl regular expression (PRX) - Examples

  12. PRX Perl regular expression (PRX) - Examples To use the PRX pattern specified with PRXPARSE use PRXMATCH function . POSITION = PRXMATCH(PATTERN_NUM,STRING); Interested in learning more. Excellent SUGI 29 paper @ http://www2.sas.com/proceedings/sugi29/265-29.pdf Title: An Introduction to Perl Regular Expressions in SAS 9 Author: Ron Cody, Robert Wood Johnson Medical School, Piscataway, NJ

  13. Questions?

More Related