Sunday, November 29, 2009
SAS Display Manager Commands
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
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
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;
Sunday, October 18, 2009
Saturday, October 17, 2009
SAS Tip_less code: Assigning 1 or 0 to flag variable
Many SAS programmers use the below code to assign a flag of 1 or 0 depending on of the test variable meets criteria or not.;
*Ex:;
*Create a test dataset;
data test;
input id age sex $;
cards;
1 25 Male
2 35 Female
3 29 Female
4 37 Male
5 32 Male
;
run;
*Most programmers use the following code to assign avalue of 1 0r 0 to flag variable;
data test1;
set test;
if sex='Male' then flag=1;
else flag=0;
run;
*Some programmers use the following code to do the same task;
data test;
set test;
flag=ifn(sex='Male',1,0);
run;
*You can write ....even simpler code than the above 2 dataset step methods.;
data test2;
set test;
flag='Male'=sex;
run;
*Or;
data test3;
set test;
flag=sex='Male';
run;
*Note: The above code does the same thing as the 1st and 2nd method;
Caveat: This code works only when you are trying to assign a value of 1 and 0 to test variable;
Thursday, October 15, 2009
Dummy Dataset or SAS Options: Which is better to insert a Zero Row?
2) Proc Freq SPARSE option
3) Proc Means COMPLETETYPES Option
4) Proc Means COMPLETETYPES Option with PRELOADFMT option.
table sitec*race /sparse out=freq (drop=percent);
run;
class sitec race;
output out =race(rename=(_freq_=count) drop=_type_);run;
VALUE $RACEF
'Asian'=3
'Black'=2
'White'=1
'American Indian or Alaska Native'=4
'Native Hawaiian or Other Pacific Islander'=5;
run;
set demo;
format race $racef.;
run;
proc means data=demo completetypes noprint nway;
class sitec race/preloadfmt;
output out =race(rename=(_freq_=count) drop=_type_);
run;
input siteid $ sex $ race $ age ;
cards;SITE1 M White 23
SITE1 F White 43
SITE1 M White 34
SITE2 M Black 21
SITE2 M White 56
SITE2 F Black 33;
run;
proc sort data=demo;
by siteid;
run;
*Without any options in proc freq;
proc freq data=demo noprint;
table siteid*race /out=nooptions (drop=percent);
run;
proc means data=demo completetypes noprint nway;
class siteid race;
output out =comptyp(where=(_stat_='N')rename=(_freq_=count) keep=siteid race _freq_ _stat_);
run;
*With Completetypes and preloadfmt options in proc means;
proc format;
VALUE $RACEF
'Asian'='Asian'
'Black'='Black'
'White'='White';
run;
data demo;
set demo;
format race $racef.;
run;
proc means data=demo completetypes noprint nway;
class siteid race/preloadfmt;
output out =race(where=(_stat_='N')rename=(_freq_=count) keep=siteid race _freq_ _stat_);
run;
Output:
Wednesday, October 7, 2009
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...