SAS Global Forum 2008 Foundations and Fundamentals Paper 181-2008 Hidden Tools You Didn’t Know You Had: Code Generating Windows Janet Stuelpner, Left Hand Computing, New Canaan, CT ABSTRACT Many SAS® tools help you generate code. They can make coding easier and less tedious. This generated code can be a starting point that you can embellish or enhance. The Reports Window is an interactive application used to produce simple or complex reports online quickly. With minimal effort, you can manipulate the variables and columns, and then capture the code to create the DEFINE statements and set up the environment. The SQL Query Window is an interactive interface that enables you to build, save, and run queries without knowing SQL or using PROC SQL. The query that you build in the SQL Query Window is passed to PROC SQL for processing when you run the query. The Import/Export Wizards transfer data between external data sources and SAS data sets. The wizards present simple windows that guide you through the process, making a complex or infrequent task simpler to perform. This paper and presentation shows you how to create simple reports and queries, how to write to external data sources, and how to capture the code. INTRODUCTION Sometimes we find that the creation of a program is tedious, labor intensive and a manual process. Wouldn’t it be nice if we could get something else to do the majority of the work and all we have to do is grab the code and enhance it for a specific purpose? Well, SAS has a number of windows and wizards that can get you started and write the code for you. All you need to do is tap into the power of the wizard and you are on your way. I will show you how to do it. Once you get started, you will be on your way. ENVIRONMENT SETUP There are certain things that must be done to get the most out of the code generation windows and wizards. The tables that will be available to you need to be defined before you open the code generation window or start the wizard. Therefore, you must run all of the FILENAME statements that define where your data resides before you invoke any of the windows or wizards. Any user written formats must be defined as well. If that requires allocating a format library or running a PROC FORMAT, it also must be done before the windows are opened. If you want specific titles and/or footnotes, you can use TITLE and/or FOOTNOTE statements to create the titles so that the can be seen in the window. Another thing that might be helpful is the definition of any options that you want to be in effect during your session. This might include nodate, nonumber or setting the linesize and pagesize. QUERY WINDOW The Query window is an interactive interface that makes accessing and reviewing data very simple. The types of data that can be accessed are numerous and include SAS tables, SAS views and if you have SAS/ACCESS® software installed, you can access relational database tables (RDBM) by using the PROC SQL pass-through. Some of the SAS/ACCESS interfaces allow you to define your data using a LIBNAME engine and assigning a libref to the table. Another thing that is possible is accessing remote host tables. This can be done if SAS/Connect® is installed on your system. As you can see there are many ways to access data from many different sources. The first things that you will see when you open the query window are the choices of tables based on the LIBREF that you have defined in your session. 1 SAS Global Forum 2008 Foundations and Fundamentals By using queries, we can retrieve data as seen above. The query window allows you to build the query, save the query and run the query. The wonderful thing is that you don’t need to be familiar with Structured Query Language (SQL) to create and run the query. You can choose what actions to use on the data. You can customize the data using any format that is defined to your SAS® session and you can change the labels online. The drop down pmenus in the program editor will allow you to gain access to the query window. The Query window, as with all windows, has PMENUS that are specific to this window. These are: FILE, VIEW, TOOLS, PROFILE. From the FILE menu you can import data from other data sources (e.g., excel or CSV files), list or include other queries so that you can build upon a query that was created previously, save the query or create a table or view. From the VIEW menu you can build different parts of the query. From the TOOLS menu, you can run the query or save the query. And from the PROFILE menu, you can change the profile of the query window. The first window that you will see shows you what tables are available to the session. From this window you will choose a table(s) and from the next window you will choose the columns for your query. When you are done with your query, you can see the code that was developed to create the query. The choice is yours as to how you want to save the code. If you save the code as a SAS file, you can bring the code into a program editor window and enhance or modify it. In the diagram below, you can see how there is a drop down menu where you can set any WHERE conditions to subset your data, use the DISTINCT option to provide only unique values of a specific field, set the sort order with the SQL ORDER BY statement or set up a HAVING condition for a group. 2 SAS Global Forum 2008 Foundations and Fundamentals Another quality of the query window is that you can use PROC REPORT to design a report without exiting the query window. REPORT WINDOW This is also an interactive interface. You can point and click your way to simple or complex reports. You can manipulate your data in the window and then capture the code. There are several ways in which to open the REPORT window through the pmenus in the program editor. Tools Report Editor Solutions Reporting Design Report Once the method is chosen, a window opens that shows you the choices of the datasets that are available for inclusion in the REPORT window. All of the librefs that are defined to your session will be included in the window on the left. When you click on one to select that file, the tables in that file are listed in the window on the right. Another method is to write code that will open the REPORT window. If you are using this method, you will need to specify the exact dataset on which you want to create a report. proc report data=myfile.mydata; run; 3 SAS Global Forum 2008 Foundations and Fundamentals Through the ROPTION window, you can tailor the environment for the report. Tools Options Report If you would like the column headers centered, here is the place to accomplish this task. Other items include skipping lines after the header, underlining the header, setting the linesize for the report, what character to use as the split character for the labels, etc. The DEFINITION window allows you to change all of the DEFINE statements for the columns in your report. If you want, you can change the color of the data in a column, you can choose to invoke the NOPRINT option which allows you to use a variable without it being printed on the report, the format of the variables can be changed, the labels can be specified, the usage of the variable specified (i.e., display, across, group, order, analysis or computed). This is also one of the places where you can create a COMPUTE block for a variable. If you click on EDIT PROGRAM, it opens up another window in which you can write the code to accomplish the creation of a new variable. You can also add a new variable that is not in the original dataset using the EDIT PMENU. You can add a data column, create a new statistic or add a computed column. Although you have the ability to subset your data online with a WHERE or a WHERE ALSO, this will not be captured in the code at the end of all of your manipulations. 4 SAS Global Forum 2008 Foundations and Fundamentals IMPORT/EXPORT WIZARD To bring in data from other data sources (i.e., Excel, Oracle, DB2) all you need to do is use the Import Wizard. If you would like to output the data to one of these file types, you would use the Export Wizard. If you have SAS/ACCESS, you can import from those files that are defined by your license. If you do not, you can still import comma delimited files along with files that have other delimiters. The Import and Export Wizards are a series of windows will guide you through the process of moving data from place to place to/from a SAS dataset. To create a SAS dataset you will need to use the Import Wizard. To start the process, drop down the FILE menu and click on IMPORT, choose your data source type, choose the destination file, provide a file path in which to save the code and when FINISH is clicked, the dataset is created and the code is saved. The process to create an external file is similar. In this case, the Export Wizard is used. Drop down the FILE menu and choose Export, then choose a data source, in this case a SAS dataset, select the output data type, complete the window that requests specific options, fill in the path where you want the program to be saved and click FINISH. CONCLUSION There are so many ways that you can use SAS to help you write your programs. There is so much to explore within each of the windows and wizards .You can be creative in the use of the window and then capture the code. I have shown you just a few of the ways that you can have SAS write the code. The rest is up to you. 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. Other brand and product names are trademarks of their respective companies. 5 SAS Global Forum 2008 Foundations and Fundamentals ACKNOWLEDGMENTS I would like to thank my husband Bob for his unending support and tireless proofreading comments. Without his care, fortitude and encouragement, I could not have successfully completed my paper. REFERENCES SUGI 29 Proceedings, Getting up to Speed with PROC REPORT, Kim Stinson LeBouton Delwiche, Lora and Slaughter, Susan,2003, The Little SAS® Book: A Primer, Third Edition, Cary, NC, SAS Institute Inc SAS Institute Inc.2004. SAS 9.1 SQL Query Window Users Guide Cary, NC, SAS Institute Inc. AUTHOR CONTACT Janet Stuelpner Left Hand Computing 326 Old Norwalk Road New Canaan, CT 06840 (203) 966-7520 voice (203) 966-8027 fax [email protected] 6
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
advertisement