SAS OnlineTutor®: Advanced SAS®
Friday, December 11, 2009
Friday, December 4, 2009
tod8. and picture formats: How Can I Find a Time Format that Does Not Remove the Leading Zero e.g. Time5
How Can I Find a Time Format that Does Not Remove the Leading Zero e.g. Time5
(output printed as 09:36 instead of 9:36)?
I have found an intersting solution to this problem in http://www.sas.com/; direct link
(Suggested by Stephen Hoar, Lloyds TSB)
There is currently no time format that puts leading zeros automatically in time values. But there are a number of ways of achieving this, below are some examples.
Example 1:
Create your own custom format using the following syntax. Then format your data values using the user defined format.
proc format ;
picture military other = '%0H:%0M:%0S' (datatype=time) ;
run ;
data test;
x= '9:36't ;
format x military8. ;
put x=;
run ;
x=09:36:00
Example 2:
You can also use the TODw.d format which does write leading zeros, but the original value must be a SAS datetime value. To convert your time values to datetime values use the DHMS function. In the DHMS function insert the value: 0 date, 0 hours, 0 minutes, and then the SAS time value as the number of seconds.
Then format the new variable with the TODw.d format and you will have the correct time, including the leading zeros.
data test;
x='9:36't;
y=dhms(0,0,0,x);
format y tod8.;
put y=;
run;
y=09:36:00
Have a look at the following Technical Support website for further examples of using Date & Time functions and formats: http://support.sas.com/techsup/sample/functions.html
SAS Macros that Convert a Directory of Transport Files
There is a set of SAS macros, converts a directory of transport files to a directory of SAS data sets and format catalogs (and vice versa). To see how to invoke the macros, look at the test following the last macro. The macros make the assumption that transport files created from data sets have the extension .xpt, and transport files created from format catalogs have the extension .xpf.
%expfmts : This macro will convert an existing format catalog into a data set in transport format.
%expdset: This macro will convert an existing SAS data set into a transport file.
%impfmts: This macro will convert a transport CNTLOUT data set into a native format catalog.
%impdset: This macro will convert a transport data set into a native SAS data set.
%getnames: This macro will create a SAS data set consisting of a variable called FILENAME. There will be one observation for each file in the specified directory with the specified extension.
Direct link: http://www.sas.com/govedu/fda/macro.html
Sunday, November 29, 2009
SAS Display Manager Commands
In my view, Display Manager commands didn’t get much attention of SAS programmers as they should be. It may be because...
1) SAS Documentation has very little information about how to use this facility.
2) Even Google searches aren’t helpful enough.
Here is the list of Display Manager Commands I know…
dm"log; clear; out; clear;";*Clears Output and Log Window;
dm "vt work.dsn" ; *Opens the dataset DSN in a View table window;
dm "vt &syslast"; *Opens the dataset recently created;
dm 'next viewtable:work.dsn; end;';*Closes the VT window of DSN;
dm 'keydef f12 submit';*Assigns the submit command to the F12 key ;
*Assigns clear log and output commands to F2 Key;
dm "keydef F2 'cle log; cle output; submit'";
*applies detail view to explorer window;
dm "next explorer; detail";
dm "next log; detail"; *Opens the Log Window;
dm "next output; detail"; *Opens the output Window;
dm "next editor; detail"; *Opens the Editor window;
dm 'next VIEWTABLE:; end;'; *Closes all opened viewtable windows;
dm 'odsresults' clear ; * Clears the Results window;
dm 'log off'; *Closes the LOG window;
dm "VT libname.dataset COLHEADING=NAMES";
VT=View Table.
COLHEADING=NAMES option displays column names as column headings instead of column labels which is default.
read more about DEXPORT and DIMPORT DM commands:
http://studysas.blogspot.com/2009/06/dexport-and-dimport-display-manager.html
dm: Display Manager
vt: View Table
keydef: Key Definition
1) SAS Documentation has very little information about how to use this facility.
2) Even Google searches aren’t helpful enough.
Here is the list of Display Manager Commands I know…
dm"log; clear; out; clear;";*Clears Output and Log Window;
dm "vt work.dsn" ; *Opens the dataset DSN in a View table window;
dm "vt &syslast"; *Opens the dataset recently created;
dm 'next viewtable:work.dsn; end;';*Closes the VT window of DSN;
dm 'keydef f12 submit';*Assigns the submit command to the F12 key ;
*Assigns clear log and output commands to F2 Key;
dm "keydef F2 'cle log; cle output; submit'";
*applies detail view to explorer window;
dm "next explorer; detail";
dm "next log; detail"; *Opens the Log Window;
dm "next output; detail"; *Opens the output Window;
dm "next editor; detail"; *Opens the Editor window;
dm 'next VIEWTABLE:; end;'; *Closes all opened viewtable windows;
dm 'odsresults' clear ; * Clears the Results window;
dm 'log off'; *Closes the LOG window;
dm "VT libname.dataset COLHEADING=NAMES";
VT=View Table.
COLHEADING=NAMES option displays column names as column headings instead of column labels which is default.
read more about DEXPORT and DIMPORT DM commands:
http://studysas.blogspot.com/2009/06/dexport-and-dimport-display-manager.html
dm: Display Manager
vt: View Table
keydef: Key Definition
Friday, November 20, 2009
Proc SQL for SAS Programmers
Yesterday I came across a website BLINK7. It is a great site to browse and to get help to improve your SAS knowledge in Proc SQL and Base SAS. This website offers a lot of information in the form of sample codes and tutorials on different topics in SAS.
SQL for SAS Programmers - Introduction
What is SQL?
SQL stands for Structured Query Language and was designed for development and maintenance within a Database Management System (DBMS). A DBMS consists of one or more tables of data, typically joined in a hierarchical fashion, and a series of programs for organizing the data.
Typical tasks performed with SQL code include the following:
Comparing SAS steps and PROC SQL_ Coding and Performance -
Basics of SAS PROC SQL -
SQL for SAS Programmers - Introduction
What is SQL?
SQL stands for Structured Query Language and was designed for development and maintenance within a Database Management System (DBMS). A DBMS consists of one or more tables of data, typically joined in a hierarchical fashion, and a series of programs for organizing the data.
Typical tasks performed with SQL code include the following:
- Retrieve (or query) data from one or more data tables
- Manipulate data within existing tables
- Define new tables and create data within new table
- Alter existing table definitions
- Set permissions for different users to access existing tables
The first part of this tutorial deals with using the PROC SQL statement to perform basic data extraction. Screenshots of the code and output are included. Readers who wish to follow along on their own systems or copy the code can download the files provided below (right click and select “save as” or “save link as”):
read more at:....
(download) SAS Code for Tutorial Part 1
(download) SAS Data: Transactions
(download) SAS Data: Payment Types
(download) SAS Data: Staff
SAS Tutorial: Creating Categories with PROC FORMAT
SAS Tutorial: Loading Tab-Delimited Files
source: www.blink7.com
Comparing SAS steps and PROC SQL_ Coding and Performance -
Basics of SAS PROC SQL -
Tuesday, November 3, 2009
Using ODS to Create Customised Output
Using the SAS Output Delivery System (ODS), you can create, customise, and manage HTML output in any operating environment by submitting programming statements. After creating HTML files, you can view them using Internet Explorer, Netscape Navigator, or any Web browser that fully supports HTML 3.2.
ODS gives you new formatting options and makes procedure output much more flexible. With ODS, you can easily create HTML, RTF, PCL, PS, XML, Latex and PDF output, an output data set of procedure results and traditional SAS listing output. Also, ODS stores your output in its component parts (data and table definition) so that numerical data retains its full precision.
Procedure output is divided into components, or output objects. Depending on the procedure that you run you might have one or several output objects created. For example proc print would create just one output object but proc univariate would produce multiple output objects. ODS stores a link to each output object in the results window. Using ODS programming statements we can control what output objects we are interested in and what ODS destinations we want to send them to.
In order to start creating HTML, RTF, PDF files etc. you will need a few ODS statements to get you started. By default SAS output still goes to the output window. In order to send the output elsewhere you need to open the appropriate destination. The example below turns off the listing destination (the output window) and opens the HTML destination so that it is ready to receive our output. When the HTML destination is closed the class.html file is created and the HTML destination is closed:
Ods listing close;
Ods html body='c:\myreports\class.html';
Proc print data=sashelp.class;
run;
Ods html close;
Ods listing;
Read more.....
ODS gives you new formatting options and makes procedure output much more flexible. With ODS, you can easily create HTML, RTF, PCL, PS, XML, Latex and PDF output, an output data set of procedure results and traditional SAS listing output. Also, ODS stores your output in its component parts (data and table definition) so that numerical data retains its full precision.
Procedure output is divided into components, or output objects. Depending on the procedure that you run you might have one or several output objects created. For example proc print would create just one output object but proc univariate would produce multiple output objects. ODS stores a link to each output object in the results window. Using ODS programming statements we can control what output objects we are interested in and what ODS destinations we want to send them to.
In order to start creating HTML, RTF, PDF files etc. you will need a few ODS statements to get you started. By default SAS output still goes to the output window. In order to send the output elsewhere you need to open the appropriate destination. The example below turns off the listing destination (the output window) and opens the HTML destination so that it is ready to receive our output. When the HTML destination is closed the class.html file is created and the HTML destination is closed:
Ods listing close;
Ods html body='c:\myreports\class.html';
Proc print data=sashelp.class;
run;
Ods html close;
Ods listing;
Subscribe to:
Posts (Atom)
Learn how to view SAS dataset labels without opening the dataset directly in a SAS session. Easy methods and examples included!
Quick Tip: See SAS Dataset Labels Without Opening the Data Quick Tip: See SAS Dataset Labels With...
-
1) What do you know about CDISC and its standards? CDISC stands for Clinical Data Interchange Standards Consortium and it is developed ke...
-
Comparing Two Approaches to Removing Formats and Informats in SAS Comparing Two Approaches to Removing Formats...
-
USE OF THE “STUDY DAY” VARIABLES The permissible Study Day variables (--DY, --STDY, and --ENDY) describe the relative day of the observ...