Prepared by: Luigi Muro – Consultant

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Advertisements

Examples from SAS Functions by Example Ron Cody
Chapter 2 Programming by Example. A Holistic Perspective Three sections separated by blank lines. Program comment File: FileName.java
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
CPS120: Introduction to Computer Science INPUT/OUTPUT.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 1 Overview 8.1 An Array Type for Strings 8.2 The Standard string.
C Language Elements (II) H&K Chapter 2 Instructor – Gokcen Cilingir Cpt S 121 (June 22, 2011) Washington State University.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
UNIX Filters.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Creating SAS® Data Sets
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Chapter 5 new The Do…Loop Statement
Expressions and Interactivity Chapter 3. 2 The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Often.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 10:Processing Macro Variables at Execution Time 1 STAT 541 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
1 Perl Regular Expressions in SAS 9 Ruth Yuee Zhang, CFE Jan 10, 2005.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 Pearson Education, Inc. All rights reserved Formatted Output.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
General Programming Introduction to Computing Science and Programming I.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
C Programming Lecture 5 : Basic standard I/O Lecture notes : courtesy of Ohio Supercomputing Center, science and technolgy support.
Type Conversions Implicit Conversion Explicit Conversion.
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Instructor: Craig Duckett Lecture 08: Thursday, October 22 nd, 2015 Patterns, Order of Evaluation, Concatenation, Substrings, Trim, Position 1 BIT275:
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
TASS Meeting Setting GuessingRows when Importing Excel Files September 19th, 2008 Setting GuessingRows when importing Excel Files Dr. Arthur Tabachneck,
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
1 CSE 2337 Chapter 7 Organizing Data. 2 Overview Import unstructured data Concatenation Parse Create Excel Lists.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
02/03/ Strings Left, Right and Trim. 202/03/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
Files A collection of related data treated as a unit. Two types Text
Bioinformatics Introduction to Perl. Introduction What is Perl Basic concepts in Perl syntax: – variables, strings, – Use of strict (explicit variables)
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 25 By Tasha Chapman, Oregon Health Authority.
Basic SAS Functions in Version 8.2 Kim Michalski Office of the Actuary Rick Andrews Office of Research, Development, and Information.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
LINGO TUTORIAL.
28 Formatted Output.
C Formatted Input/Output
Introduction to C CSE 2031 Fall /3/ :33 AM.
Error Handling and Validation
CS150 Introduction to Computer Science 1
Trainer: Bach Ngoc Toan– TEDU Website:
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Presentation transcript:

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

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.

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

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(1350.624, 8.2))); Version 9 (Reduce code complexity) combine = catx(‘ ‘, Char1, Char2); remblanks = strip(put(1350.624, 8.2));

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);

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

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’;

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.

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;

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; ... ;

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"

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 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

Questions?