Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepared by: Luigi Muro – Consultant

Similar presentations


Presentation on theme: "Prepared by: Luigi Muro – Consultant"— Presentation transcript:

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

2 Enhancements to the FORMAT Procedure
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 New Character SAS Functions
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 Concatenating Strings
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( , 8.2))); Version 9 (Reduce code complexity) combine = catx(‘ ‘, Char1, Char2); remblanks = strip(put( , 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 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: 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 Metacharacter Description
* Matches the previous subexpression zero or more times cat* matches "cat", "cats", "catanddog" + Matches the previous subexpression one or more times \d+ matches one or more digits ? Matches the previous subexpression zero or one times hello? matches "hell" and "hello" . (period) Matches exactly one character r.n matches "ron", "run", and "ran" \d Matches a digit 0 to 9 \d\d\d matches any three digit number \D Matches a non-digit \D\D matches "xx", "ab" and "%%" ^ Matches the beginning of the string ^cat matches "cat" and "cats" but not "the cat" $ Matches the end of a string cat$ matches "the cat" but not "cat in the hat"

12 PRX Perl regular expression (PRX) - Examples
Function Matches Does not Match PRXPARSE("/cat/") "The cat is black" "cats" PRXPARSE("/^cat/") "cat on the roof" "The cat" PRXPARSE("/cat$/") "There is a cat" "cat in the house" To use the PRX pattern specified with PRXPARSE use PRXMATCH function . POSITION = PRXMATCH(PATTERN_NUM,STRING); Interested in learning more. Excellent SUGI 29 Title: An Introduction to Perl Regular Expressions in SAS 9 Author: Ron Cody, Robert Wood Johnson Medical School, Piscataway, NJ

13 Questions?


Download ppt "Prepared by: Luigi Muro – Consultant"

Similar presentations


Ads by Google