Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK Define your Own SAS® Command Line Commands Duong Tran – Independent.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Axio Research E-Compare A Tool for Data Review Bill Coar.
Chapter 9: Introducing Macro Variables 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Macro simple idea of textual substitution useful when you need a group of instructions or directives frequently.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
PHP (2) – Functions, Arrays, Databases, and sessions.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Let SAS Do the Coding for You! Robert Williams Business Info Analyst Sr. WellPoint Inc.
Introduction to scripting
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
Copyright © 2010, Meta-Xceed, Inc. All rights reserved. BI Flash and all other Meta-Xceed Inc. product or service names are registered trademarks or trademarks.
Copyright © 2006, SAS Institute Inc. All rights reserved. Enterprise Guide 4.2 : A Primer SHRUG : Spring 2010 Presented by: Josée Ranger-Lacroix SAS Institute.
Introduction to Shell Script Programming
Stacking Rich Text Format (RTF) - %SRiT Duong Tran – Independent Contractor, London, UK Stacking Rich Text Format (RTF) - %SRiT Duong Tran – Independent.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
INTRODUCTION TO SAS MACRO PROCESSING James R. Bence, Ph.D., Co-Director Quantitative Fisheries Center Professor Department of Fisheries and Wildlife March.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
1 Back Up with Each Submit One approach for keeping a dynamic back up copy of your current work.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
5/30/2010 SAS Macro Language Group 6 Pradnya Nimkar, Li Lin, Linsong Zhang & Loc Tran.
Macro Overview Mihaela Simion. Macro Facility Overview Definition : The SAS Macro Facility is a tool within base SAS software that contains the essential.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
Use Your Favourite Program Editor Duong Tran – Independent Contractor, London, UK Use Your Favourite Program Editor Duong Tran – Independent Contractor,
SAS ODS (Output Delivery System) Donald Miller 812 Oswald Tower ;
Macro Variable Resolution Enio Presutto York University, Toronto, Canada.
Introduction to SAS Macros Center for Statistical Consulting Short Course April 15, 2004.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
Chapter Three The UNIX Editors.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
– Intermediate Perl 1/6/ Intermediate Perl - POD, parameters and configuration Intermediate Perl – Session 7 · POD –
Chapter 7: Macros in SAS  Macros provide for more flexible programming in SAS  Macros make SAS more “object-oriented”, like R 1 © Fall 2011 John Grego.
FOR MONDAY: Be prepared to hand in a one-page summary of the data you are going to use for your project and your questions to be addressed in the project.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Scion Macros How to make macros for Scion The Fast and Easy Guide.
1 Week # 4 Introduction to PDM PDM is a workbench environment that lets programmers and system operators navigate the three levels of the AS/400’s object-based.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
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.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc.
Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables.
CS 330 Class 7 Comments on Exam Programming plan for today:
Department of Computer Engineering
Lecture 7 Introduction to Shell Programming
Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Chapter 5: Enhancing Your Output with ODS
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Intro to PHP & Variables
PHP.
Passing Simple and Complex Parameters In and Out of Macros
Writing Robust SAS Macros
Presentation transcript:

Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK ABSTRACT SAS ® provides a number of Command Line commands and some of these are frequently used. For example the commands fsv, lib, var etc. But did you know that you can create your own? This paper will show how you can customize repetitive actions of a particular task into a Command Line command. Keywords: gsubmit, cmdmac INTRODUCTION SAS allows you to customize a sequence of actions into a simple command which is very useful. For examples often you want to know – what are the variables in the dataset, the definition for a format etc. You could define a macro for each of these then assign it to function keys, but a major drawback with this technique is that you will soon run out of function keys. A better way is to design a command that you can execute at the command line, just like those that are already existed in SAS. The SAS gsubmit command and the cmdmac option make this extension possible. DEFINING SAS COMMAND LINE COMMANDS The desire is to define commands in the following form; COMMAND | ‘ ’>. That is a command should be able to take parameters (options) and therefore make its versatile. Similarly to the ls command in UNIX for example, where its can takes options - la etc. Here is a schematic of the design for defining Command Line commands follow by a complete practical example. Note the advantage of this design is that your command macro is just a “normal” macro like any others, that is to say you can turn any macros you already have into a Command Line command if so wish. You can execute this Command Line as: Examples Note: string in quotes will be treated as a single parameter. This possibility is useful because you can pass a string as a single parameter and then parse it inside the command call macro. DISPLAY THE RESULT OF THE COMMAND The above example send the result to a file but there will be commands where you would prefer to send the result to the screen. And here are a number of ways to do this. 1. Send to the output panel with Proc Print, Report etc 2. Send the result to a text file and use Proc Fslist, Notepad or Nedit etc to display this text file 3. Send the result to a HTML file via ODS and use a Web Browser display this HTML file SOME IDEAS FOR MORE COMMANDS How about a command com to list the available commands? Command Line Commands man - to display available commands man - to display the command documentation fmt - to display the definition of the format etc.. the list is up to your imagination CONCLUSION The technique shown in the paper allows you to define 'any' Command Line command imaginable. It’s simple yet powerful. That is a Command Line command is just a macro like any other macro. Also note the SAS x statement can call other applications and therefore a command could be written in other languages for example PERL. REFERENCES [1] Tran, Duong “Improving Programming Efficiency for Statisticians and Programmers with Customization” – PSI 2010 [2] Benjamin, Neely “COMMAND Your Session: SAS® Commands and Command-Style Macros – SAS Global Forum 2011 [3] DeVenezia,Richard A. “SAS® Explorer: Use and Customization” – NESUG 18 CONTACT INFORMATION Author Name: Duong Tran Web: *klm_call.sas; options cmdmac; * must have option; * send data to excel; %macro xl(dset, vars, ofile) / cmd; gsubmit "%inc 'klm_sas2xl.sas';"; output; %mend; *more commands etc.. *klm_sas2xl.sas; %macro sas2xl_klm; %inc "sas2xl.sas"; %sas2xl(dset = &dset,vars = %sysfunc(compress(&vars, %str(%"%'))),ofile = &ofile ); %mend; %sas2xl_klm; *sas2xl.sas; %macro sas2xl(dset =,vars =,ofile = ); %local vlist lword l1 l2; %let vlist = &vars; %let lword = %scan(&vlist, -1); * if option specified; %if %datatyp(&lword) = NUMERIC %then %do; %let l1 = %length(&vlist); %let l2 = %length(%scan(&vlist, -1)); %let vlist = %substr(&vlist, 1, %eval(&l1 - &l2)); %end; * delete the view initially; proc datasets nolist library=work mt=view; delete dsview; quit; * create dataset view; data dsview / view=dsview; retain &vlist; %if &lword = 1 %then %do; set &dset(keep=&vlist); %end; %else %do; set &dset; %end; run; * if output file is not specified then default it to this location; %if &ofile eq %then %do; %if %upcase(%scan(&SYSSCP,1))= SUN %then %let ofile = %sysget(HOME)/temp.xls; %else %if %upcase(%scan(&SYSSCP,1))=WIN %then %let ofile = c:\temp.xls; %end; %put output file: &ofile; * export view to excel; proc export data=dsview outfile="%scan(&ofile, 1, %str(.))" dbms=xls replace; run; %mend; PhUSE 2011 – PP02 Examples This is a complete example to send the specified dataset to an Excel file. The fundamental is the cmdmac and cmd options that allow parameters entered at the Command Line to be taken into a macro as macro variables. See (dset, vars, ofile) below.