Tag Archives: SAS interface

SAS Programmers Tools

Are you new to SAS and wondering how to write SAS programs?

Most SAS programmers use the built-in SAS enhanced editor for their daily works. Sometimes, this editor is replaced by the code editor of SAS Enterprise Guide which provide other features like the Log tab, Output data tab and Results tab. However, some SAS users like their text editor to be very customizable and full of features which may or may not be in the enhanced editor.

If you find that your current editor is insufficient in handling your work you are not alone. We have found some alternative editors and below are some of the text editors I have come across that you can use instead of the pre-built SAS editor:

TextPad: is a full-featured text editor offering a spelling checker, macros, and powerful formatting and file-storage options from Helios Software Solutions.

This is a great program – it’s a powerful text editing tool that’s really comfortable to use. Textpad has a very clean, simple interface that deals only with text – that is, it doesn’t let you change font halfway down the page, or make text underlined or italic; it’s built purely to deal with the content, and does that job EXTREMELY well.

These features are excellent for SAS macro programming and SCL programming. Besides these, Textpad has a built-in compiler for Java which allows for rapid switching to Java coding that is occasionally required.

Below is a screen shot of the editor:

Textpad has many macro features that allows for repetitive actions to be recorded and recycled easily.

Crimson Editor is a professional source editor for Windows Open source from Ingyu Kang and one of the most popular editor available for programmers to use.

This editor also allow programmers to install schematics (define tools) that will highlight sections of your SAS programs.

Below is a screen shot of the editor:

In summary, there are many options to help a SAS programmer increase efficiency, write cleaner code, or make SAS life easier. There are other popular editors such as Emacs but I don’t have a lot of experience using it thus I cannot comment on it properly. Your style of programming will influence the type of editor you will use.

Anayansi Gamboa has an extensive background in clinical data management as well as experience with different EDC systems including Oracle InForm, InForm Architect, Central Designer, CIS, Clintrial, Medidata Rave, Central Coding, OpenClinica Open Source and Oracle Clinical.

Advertisements

How to Use SAS – Lesson 6 – SAS Arithmetic and Variable Creation

This video series is intended to help you learn how to program using SAS for your statistical needs. Lesson 6 introduces the concept of SAS arithmetic in the DATA STEP. I discuss how one can add, subtract, divide, multiply, or create their own formulas for variables in the data. I also discuss using SAS arithmetic to create new variables based on mathematical transformations of old variables, which may sometimes aid in meeting the assumptions of statistical tests. Finally, I provide basic examples of each of these methods.

Helpful Notes:

1. SAS uses many of the same arithmetic operators to add, subtract, divide and multiply as other programming languages and basic algebra.

2. Arithmetic operations on variables affect the entire list of observations. So be careful in operating with existing variables and make new variables if you can afford to.

3. The varnum ;option on the PROC CONTENTS statement can allow you to see the variables listed in the order they were created.

Today’s Code:

data main;
input x y;
cards;
1 2
3 4
5 6
7 8
;
run;

proc print data=main;
run;

data new_main; set main;
a = x + y;
b = x – y;
c = x * y;
d = x / y;
e = x ** y;
f = ((x + y) * (x – y));
run;

proc contents data=new_main varnum;
run;

proc print data=new_main;
run;

-FAIR ;USE-
“Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for “fair use” for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use.”

Anayansi Gamboa has an extensive background in clinical data management as well as experience with different EDC systems including Oracle InForm, InForm Architect, Central Designer, CIS, Clintrial, Medidata Rave, Central Coding, OpenClinica Open Source and Oracle Clinical.

How to Use SAS – Lesson 4 – Merging Data Sets

This video series is intended to help you learn how to program using SAS for your statistical needs. Lesson 4 introduces the concept of merging SAS data sets using a variety of methods. I discuss how one can merge two or more data sets in the DATA STEP using the SET statement. I also describe how one can use the MERGE statement to bring two or more datasets together that may have a common index variable. Furthermore, I describe the SORT procedure (PROC ;SORT) that must be used with the MERGE statement. Finally, I provide basic methods of merging data sets using PROC SQL.

Helpful Notes:
1. Use one SET statement when you have the same variables, but different observations.

2. Use two SET statements when you have different variables, but the same observations.

3. Use the MERGE statement when you have a common index variable, and any new variables or observations.

4. The MERGE statement first requires that you use the SORT procedure (PROC SORT) to sort on the index variable before merging.

5. Make sure that you add the BY statement after the MERGE statement in your DATA step or you will have a new dataset that is merged incorrectly.

6. PROC SQL is an advanced method of merging data that can be very powerful for large datasets. It uses different kinds of “JOINS” that I will provide more information on in a later video.

Today’s Code:
data main;
input x y z;
cards;
1 2 3
7 8 9
;
run;

/* 1. Use one SET statement when you have the same variables, but different observations */
data more_people;
input x y z;
cards;
4 5 6
3 6 9
;
run;

data final;
set main more_people;
run;

proc print data=final; run;

/* 2. Use two SET statements when you have different variables, but the same observations */
data more_vars;
input a b c;
cards;
20 40 60
10 20 30
;
run;
data new_final;
set main;
set more_vars;
run;

proc print data=new_final; run;

/* 3. Use the MERGE statement when you have a common index variable, and any new variables or observations */
data more_vars_and_people;
input x a b c;
cards;
1 20 40 60
7 10 20 30
2 11 12 13
3 14 15 16
;
run;

* The MERGE statement requires that you use an index variable to merge on (e.g. an ID variable).;
* Thus, you must SORT your data BY that index variable.;
proc sort data=main;
by x;
proc sort data=more_vars_and_people;
by x;
run;
data merged_final;
merge main more_vars_and_people;
by x;
run;

proc print data=merged_final; run;

/* 4. SQL is an advanced programming language for databases. Here, I provide a basic example to merge the two datasets using a LEFT JOIN. I will include more information about JOIN types in a follow up video. For now, think of a LEFT JOIN as one that only includes the data from the second dataset (more_vars_and_people) that corresponds to data from the original dataset (main).
*/
proc ;sql;
create table sql_final as
select L.*, R.*
from main as L
LEFT JOIN more_vars_and_people as R
on L.x = R.x;
quit;

proc print data=sql_final; run;

-FAIR ;USE-
“Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for “fair use” for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use.”

Anayansi Gamboa has an extensive background in clinical data management as well as experience with different EDC systems including Oracle InForm, InForm Architect, Central Designer, CIS, Clintrial, Medidata Rave, Central Coding, OpenClinica Open Source and Oracle Clinical.

How to Use SAS – Lesson 2 – Creating Datasets on the Fly

This video series is intended to help you learn how to program using SAS for your statistical needs. Lesson 2 introduces some basic data step programming to define variables and specify their values for data sets containing one or more observations.

I also introduce two procedures: the PRINT procedure (PROC ;PRINT) to display the data contents in the OUTPUT window, and the CONTENTS procedure (PROC CONTENTS) to summarize the data set. Finally, I introduce the concept of libraries to show another method of inspecting the data set by physically opening it from the temporary WORK library.

Helpful Notes:

1. PROC PRINT – displays the entire data set by observation in the OUTPUT window
2. PROC CONTENTS – summarizes the properties of a data set, including an alphabetic listing of the variables and a count of the number of observations.
3. The assignment operator (“=”) directly specifies the value of a variable in the data step.
4. The INPUT statement defines one or more variables of our data set.
5. The CARDS statement specifies the values for each of the INPUT variables (in order).
6. It is a good rule of thumb to always pair the INPUT and CARDS statements together.
7. DON’T FORGET SEMI;COLONS! They end statements and without them, you will most certainly have errors arise.
8. If you have any errors, always, ALWAYS, ALWAYS check the LOG first!
9. Creating datasets “on-the-fly” just means you’re making a new dataset without bringing in the data from any other source.

Today’s Code:

data main;
input x y z;
cards;
1 2 3
7 8 9
;
run;

proc print data=main;
run;

proc contents data=main;
run;

-FAIR ;USE-
“Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for “fair use” for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use.”

Anayansi Gamboa has an extensive background in clinical data management as well as experience with different EDC systems including Oracle InForm, InForm Architect, Central Designer, CIS, Clintrial, Medidata Rave, Central Coding, OpenClinica Open Source and Oracle Clinical.

How to Use SAS – Lesson 1 – The SAS Interface

This video series is intended to help you learn how to program using SAS for your statistical needs. Lesson 1 introduces the SAS window, it’s various environments ;and what each environment does. I also provide some basic code to create a data set, make a new variable & assign it a value, and then run the print procedure (PROC PRINT) to see what the values are of each variable in the specified data set.

Helpful Notes:

Here are the five primary “environments” that SAS uses:

1. RESULTS: where output is shown in tree structure
2. EXPLORER: the interfacing environment between SAS and your computer
3. OUTPUT: the output of your code
4. LOG: the “middle-man” between you and the SAS system
5. EDITOR: where you type your code

Today’s Code:

data main;
x = 1;
y = 2;
run;

proc print data=main;
run;


-FAIR USE-
“Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for “fair use” for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use.”

Anayansi Gamboa has an extensive background in clinical data management as well as experience with different EDC systems including Oracle InForm, InForm Architect, Central Designer, CIS, Clintrial, Medidata Rave, Central Coding, OpenClinica Open Source and Oracle Clinical.