Fundamentals of Programming in SAS. James Blum

Чтение книги онлайн.

Читать онлайн книгу Fundamentals of Programming in SAS - James Blum страница 10

Автор:
Жанр:
Серия:
Издательство:
Fundamentals of Programming in SAS - James Blum

Скачать книгу

those that are not delivered. Only one should be used in any procedure, typically corresponding to whichever list of tables is shorter—those to be included or excluded. In place of the list of object names, one of the keywords of ALL or NONE can be used. ODS SELECT or ODS EXCLUDE can be placed directly before or within a procedure, and its effect is local if a list of objects is given, only applying to the execution of that procedure. If the ALL or NONE keywords are used, the effect is global, remaining in place until another statement alters it.

       The VARNUM option produces a table (Output 1.5.2B) with the same variable information as the first PROC CONTENTS but, as shown in the trace, it is a different table with a different name.

      Output 1.5.2A: Using ODS SELECT to Subset Output

Alphabetic List of Variables and Attributes
#VariableTypeLenFormatLabel
9CylindersNum8
5DriveTrainChar5
8EngineSizeNum8Engine Size (L)
10HorsepowerNum8
7InvoiceNum8DOLLAR8.
15LengthNum8Length (IN)
11MPG_CityNum8MPG (City)
12MPG_HighwayNum8MPG (Highway)
6MSRPNum8DOLLAR8.
1MakeChar13
2ModelChar40
4OriginChar6
3TypeChar8
13WeightNum8Weight (LBS)
14WheelbaseNum8Wheelbase (IN)

      Output 1.5.2B: Using ODS SELECT to Subset Output

Variables in Creation Order
#VariableTypeLenFormatLabel
1MakeChar13
2ModelChar40
3TypeChar8
4OriginChar6
5DriveTrainChar5
6MSRPNum8DOLLAR8.
7InvoiceNum8DOLLAR8.
8EngineSizeNum8Engine Size (L)
9CylindersNum8
10HorsepowerNum8
11MPG_CityNum8MPG (City)
12MPG_HighwayNum8MPG (Highway)
13WeightNum8Weight (LBS)
14WheelbaseNum8Wheelbase (IN)
15LengthNum8Length (IN)

      ODS statements can be used to direct output to various destinations, including multiple destinations at any one time. Output styles can vary across destinations, as Program 1.5.3 demonstrates by delivering the same graph to a PDF and PNG file.

      Program 1.5.3: Setting Output Destinations Using ODS Statements

      x ‘cd C:\Output’;

      ods _ALL_ CLOSE;

      ods listing;

      ods pdf file=’Output 1-5-3.pdf’;

      proc sgplot data=sashelp.cars;

       styleattrs datasymbols=(square circle triangle);

       scatter y=mpg_city x=horsepower/group=type;

       where type in (‘Sedan’,’Wagon’,’Sports’);

      run;

      ods pdf close;

       The X command allows for submission of command line statements. CD is the change directory command in both Windows and Linux, here its effect is to change the SAS working directory. The SAS working directory is the default destination for any file reference that does not include a full path—one that starts with a drive letter or name. This directory must exist to successfully submit this code; therefore, either create the directory C:\Output or substitute another that the SAS session has write access to.

       The ODS _ALL_ CLOSE statement closes all output destinations.

       The ODS LISTING statement activates the listing destination, which is the destination for all graphics files created by the SGPLOT procedure. In the SAS windowing environment the ODS LISTING statement also activates the Output window, but graphics generated by PROC SGPLOT are not displayed there.

       The ODS PDF statement opens the PDF destination specified in the FILE= option (if this option is omitted the file is automatically named). Since the file name does not reference any path, it is placed in the location specified in . A full-path reference, starting with a drive letter or name, can be given here. Commonly used destinations include PDF, RTF, HTML, and LISTING, but several others are available.

       Output 1.5.3A shows the graph generated by PROC SGPLOT and placed in the PDF file, while Output 1.5.3B shows the graphics file (a PNG file by default) generated. Note the difference in appearance between the two (and check the log)—different output destinations can have different options or styles in effect.

       The ODS PDF CLOSE statement closes the PDF destination opened in  and completes writing of the file, which includes all output generated between the opening and closing ODS statements. In general, any ODS statement that opens a destination should have a complementary CLOSE statement.

      Output 1.5.3A: Graph Delivered to PDF File

Output 1.5.3A: Graph Delivered to PDF File

      Output 1.5.3B: Graph Delivered to PNG File (Listing Destination)

Output 1.5.3B: Graph Delivered to PNG File (Listing Destination)

      While the graph in the PDF file uses the same plotting shape and cycles the colors, the one delivered as an image file cycles through both different shapes and colors. The takeaway from this example, which applies in several instances, is that not all output destinations use the same styles. In this book, graphs are shown in the form generated by direct delivery to TIF files, see Chapter Note 7 in Section 1.7 for options used to generate these graphs.

      Program 1.5.3 shows that ODS statements permit delivery of output to more than one destination at a time, and they also allow for different subsets of output to be delivered to each. While Program 1.5.3 shows that different destinations may have certain style elements that are different, it is also possible to specifically prescribe different styles to different output destinations. Program 1.5.4 opens a PDF and an RTF destination, sending different subsets of the output to each, and with different styles assigned to each.

      Program 1.5.4: Setting Multiple Output Destinations and Styles Using ODS Statements

      ods rtf file=’RTF Output 1-5-4.rtf’ style=journal;

      ods pdf file=’PDF Output 1-5-4.pdf’;

      ods trace on;

      proc corr data=sashelp.cars;

      var

Скачать книгу