Tag Archives: learn SAS

From Non-SAS Programmer to SAS Programmer Part II

Previously, we wrote about how you can become a SAS Programmer with little or no programming background.

Today, I want to share a new link where you can download SAS Studio for free and practice. I have to give a thank to Andrew from statskom for the tip. Visit his blog for more SAS tips.

Here is a quick step on what you need in order to use the SAS University version for free provided by SAS:

1- Create a SAS profile and select the environment based on your operating system in order to download the SAS® University Edition. I  chose Oracle VirtualBox. The options available are: Oracle VirtualBox in Windows, Macintosh, and Linux operating environments.

2- You will receive an email where you can you download your SAS edition as per your selected environment on step 1. Click the link. It could take up to an hour for the entire program to download.

SAS University Edition

3-Go to https://www.virtualbox.org/wiki/Downloads to install the OracleVirtualBox.

4-Add the SAS University Edition vApp downloaded on step 2 to VirtualBox step 3.

OracleVM

5-Create a folder for your data and results.

6- Start the SAS University Edition vApp

7-Open the SAS University Edition by opening your web browser and typing  http://localhost:10080. From the the SAS University Edition: Information Center, click Start SAS Studio.

There you have it! You have now access to SAS and can start practicing your new programming language.

anayansigamboa sas studio anayansigamboa sas studio anayansigamboa sas studio anayansigamboa sas studio

For more information about the SAS University Edition, see the FAQs and videos at http://support.sas.com/software/products/university-edition/index.html.

For Data Management and EDC training, please contact RA eClinical Solutions.

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 Clinica.

Disclaimer: The legal entity on this blog is registered as Doing Business As (DBA) – Trade Name – Fictitious Name – Assumed Name as “GAMBOA”.

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.

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 5 – Data Reduction and Data Cleaning

This video series is intended to help you learn how to program using SAS for your statistical needs. Lesson 5 introduces the concept of data reduction (also known as subsetting ;data sets). I discuss how one can subset a data set (i.e. reduce a data set’s number of observations) based on some criteria using the IF statement in the DATA STEP, or using the WHERE statement in a PROC STEP. I also discuss using the KEEP, DROP, and RENAME statements for reducing data to only a handful of the original variables (i.e. reduce a data set’s number of variables). Furthermore, I show how one can label variables so that descriptive information can be presented in output and value formats so that specific values are easy to understand. Finally, I provide basic examples of each of these for three hypothetical data sets.

Helpful Notes:

1. There are two places you can reduce the data you analyze; in the DATA STEP, and in the PROC STEP.

2. To subset data in the DATA STEP, use the IF statement.

3. To subset data in the PROC STEP, use the WHERE statement.

4. Another way to reduce data is to eliminate variables using a KEEP or DROP statement. This method is useful if you are creating a second data set or analytic version of your main dataset.

5. The RENAME statement simply changes a variables name.

Today’s Code:

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

proc contents data=main; run;
proc print data=main; run;

/* 1. Reduce data in the DATA STEP using a simple IF statement */
data reduced_main; set main;
if x = 1;
run;

proc print data=main; run;
proc print data=reduced_main; run;

/* 2. Reduce data in the PROC STEP using a simple WHERE statement */
proc print data=main;
where x = 1;
run;

proc print data=main; run;
proc print data=reduced_main; run;

/* 3. Reduce data in the DATA STEP by KEEPing only the variables you do want */
data reduced_main; set main;
KEEP x y;
run;

proc print data=main; run;
proc print data=reduced_main; run;

/* 4. Reduce data in the DATA STEP by DROPing the variables you don’t want */
data reduced_main; set main;
DROP y;
run;

proc print data=main; run;
proc print data=reduced_main; run;

/* 5. Clean up variables using the RENAME statement within a DATA STEP */
data clean_main; set main;
rename x = ID y = month z = day;
run;

proc contents data=main; run;
proc contents data=clean_main; run;

/* 6. Clean up variables using a LABEL statement within a DATA STEP */
data clean_main; set clean_main;
label ID = “Identification Number” month = “Month of the Year” day = “Day of the Year”;
run;

proc contents data=main; run;
proc contents data=clean_main; run;

/* 7. FORMAT value labels using the PROC FORMAT and FORMAT statements */
PROC FORMAT;
value months 1=”January” 2=”February” 3=”March” 4=”April” 5=”May” 6=”June” 7=”July” 8=”August” 9=”September” 10=”October” 11=”November” 12=”December”;
run;

data clean_main; set clean_main;
format month months.;
run;

proc ;freq data=clean_main;
table month;
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 3 – Importing External Data

This video series is intended to help you learn how to program using SAS for your statistical needs. Lesson 3 introduces the concept of permanent or external data sets and how to import them into SAS. I provide basic methods of importing permanent data sets using the INFILE ;statement and the IMPORT procedure (PROC ;IMPORT) for non-SAS based data files. I also discuss libraries and the LIBNAME ;statement to import SAS data directly using the SET statement. Finally, I show how one can save a SAS data set from the data step using LIBNAMEs in the DATA step.

Helpful Notes:

1. The LIBNAME statement is used to point SAS towards a specific folder on your computer.
2. The INFILE statement “reads” data into SAS if it is of a certain format (usually comma, space, or tab delimited).
3. PROC IMPORT – imports data of any of several different file formats into SAS.
4. The SET statement imports data from a library into SAS at the DATA STEP.
5. The library name in a data step’s data name “writes” data from SAS into your library folder using SAS’s own file format system.

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

proc contents data=main;
run;

proc print data=main;
run;

/* TEMPLATED CODE: .txt file type, with or without delimiters */
data [appropriate data set name here]; infile ;”[your file location here, including .txt extension]” LRECL=[a logical length of your data to emcompass ;ENTIRE data] DLM=’,’;
input
[variable names here]
;
run;

data infile_main;
infile “C:\My SAS Files\main.txt”;
input x y z;
run;

proc print data=infile_main;
run;

/* TEMPLATED CODE: Microsoft Excel (.xls) file type */
proc import out=[your data set name here]
datafile='[your file location here, including .xls extension]’
dbms=excel replace;
*Optional statements are below; sheet='[specify sheet to obtain]’; getnames=[yes/no – first row = variable names]; mixed=[yes/no – refers to data types, if num AND char varibles, use yes]; usedate=[yes/no – read date formatted data as date formatted SAS data]; scantime=[yes/no – read in time formatted data as long as variable is not date format];
run;

proc import out=imported_excel
datafile=’C:\My SAS Files\main.xls’
dbms=excel replace;
*Optional statements are below; sheet=’Sheet1′; getnames=yes;
run;

proc print data=imported_excel;
run;

libname home “C:\My SAS Files\”;

data sas_format; set home.main;
run;

data home.sas_format; set infile_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.

SAS Programming Tip: Formatted Input

This material is related to the type of content covered in the following courses:

SAS Programming Introduction: Basic Concepts
https://support.sas.com/edu/schedules.html?ctry=us&id=106

SAS Programming 1: Essentials
https://support.sas.com/edu/schedules.html?ctry=us&id=277

SAS Programming 2: Data Manipulation Techniques course
https://support.sas.com/edu/schedules.html?ctry=us&id=278

For more information about SAS programming, visit: https://support.sas.com/edu/courses.html?ctry=us

-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.”

Working with SAS® Enterprise Guide® Projects

-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.”

Source: http://support.sas.com/learn/ondemand/professionals

Opening SAS® Data Sets, Programs and Other Files

Learn how to open SAS data sets, programs and other files with SAS® OnDemand for Professionals: Enterprise Guide®, a learning version of SAS

-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.”

Source: http://support.sas.com/learn/ondemand/professionals