SAS language

The SAS language is a data processing and statistical analysis language.

See more on origins of SAS language at SAS System and at Barr Systems website.

Contents

Structure

The SAS language basically divides data processing and analysis into two kinds of steps.

1) Data Steps - Which manipulate data input and creation or deletion of variables .

2) Procedure Steps - Which manipulate analysis and output.The short form for each procedure step is Proc

Each line of code in SAS language ends with a ";"

Data Storage Hierarchy Data is stored in this hierarchy -

1)Libraries - Which contain datasets.

Libname Good "C:/Data/";

This creates a reference path to library named Good at storage location "C:/Data/";

2)Datasets -Which contain variables and records. Records are rows , and variables are column headers.

Datasets can be temporary (they close when you shut down the SAS Compiling software) or they can be stored to the Operating Disk File System.

data good.dataset1; (Output Dataset Name) set dataset2; (Input Dataset Name) run; (Command after each Data step)

This stores the temporary dataset named "Dataset2" into a permanent location "C:/Data/dataset1.sas7bdat ) because it uses the Reference to good as "C:/Data/"; in previous step.

Components

SAS Language has separate sub components called the Output Delivery System (ODS) , SAS Macro Language , and SAS SQL steps.

ODS system

It can output files to a variety of formats notably Excel, Rich Text (Word) and PDF.

An example of ODS code is

ODS HTML File =" Path of file storage /File Name .Extension";

Proc Step 1, Proc Step 2.... for output

ODS HTML Close;

Here Extension will be .xls (For Microsoft Excel files, .pdf for Adobe Acrobat files,.doc for Microsoft Word files,.RTF for rich text format files)

The SAS Macro language is used for repeatable steps.

Its format is explained as below

start of a macro with %MACRO namemacro(variables,...); variable with a suffix of "%" within the Macro, end of a macro with %MEND ; Calling Macro with %Namemacro(value of variable1 in N th run, value of variable2 in N th run,...);

A illustrative example of SAS Macro Language is below.

Note in SAS language comments begin with a /* and end with */

/*PROGRAM TO AUTOMATE REPORTING */

/*DECLARING THE PATH OF THE INPUT/OUTPUT FOLDER */
%let pathfile = ‘X:\Auto\AUG06-AUTOS\’ ;

/*CREATING LIBRARY NAME */

libname auto &pathfile;
run;

/*TO CONSERVE SPACE*/

options compress=yes;

/*TO MAKE LOG READABLE */
options macrogen symbolgen;

/* STARTING MACRO FOR REPEATABLE EXECUTION OF REPORT*/
%macro impmth(mth,num,emailid);

/*MANIPULATING VARIABLES TO REDUCE CHANGES */

data _null_ ;

call symput(’filepath’,”‘”||&pathfile||&mth||’.csv’||”‘” );
call symput(’unqpath’,”‘”||&pathfile||”unq”||&mth||’.csv’||”‘” );
call symput(’unqxls’,”‘”||&pathfile||”unq”||&mth||’.xls’||”‘” );
run;

/*IMPORT*/

/*IMPORTING DATA FROM CSV FILES STORED IN FOLDER DECLARED ABOVE*/
PROC IMPORT OUT= auto.&num
DATAFILE= &filepath
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
quit;

/*CREATING VARIABLE FOR DISTINGUISHING INPUT*/
data auto.#
set auto.#
&num =1;
run;

———————————————————————–

/*PROCEDURE HERE REMOVING DUPLICATES*/
proc sort data=auto.&num nodupkey;
by REFAGREEMENTID;
run;

———————————————————————–
/*EXPORT*/
/*EXPORTING DATA TO A CSV FILE*/
PROC EXPORT DATA= AUTO.&num
OUTFILE= &unqpath
DBMS=CSV REPLACE;
RUN;

/*EXPORTING DATA TO A XLS FILE*/ ODS HTML FILE=&unqxls;

proc print data=auto.#
run;
ODS HTML CLOSE;

/*EMAILING THE RESULTS*/ filename outbox email &emailid;

data _null_ ;
file outbox
to=(&emailid)/* Overrides value in filename statement */
cc=(&emailid)
subject=’File from’
attach=(&unqxls)
;
put ‘Hi,’;
put ‘This is an integrated approach to automating reports’;
put ‘It works great!’;
run;
%mend;

/*INVOKING THE MACRO*/ /*HERE ‘Ahmedabad’ IS THE INPUT FILE WHILE Ahd IS THE OUTPUT FILE*/

/*HERE ‘good@sas.com’ IS THE EMAIL ID TO BE MAILED THE REPORT*/
%impmth(’Ahmedabad’,Ahd,’good@sas.com’);

The SAS SQL steps are simple combinations of Structured Query Language, SQL with suffix of PROC SQL.

SAS User Groups are User Groups of SAS Language ,some of them with and some of them without active financial support of SAS Institute.

This includes the http://www.sascommunity.org ,http://www.basas.com,http://www.labsug.org,http://www.views-uk.demon.co.uk and http://www.philasug.org .

The SAS -L user group list is the biggest e-group for SAS Language Users for technical help.

The SAS compiler includes modules originally written in machine language as well as PL/1 (see SAS System) and rewritten much more recently in C/C++. Java appears to have a role as well in very recent extensions such as hash objects. The SAS Data step is a Turing-complete programming language in that it supports assignments, alternations, and iterations (the control elements of all procedural programming languages). SAS PROC SQL extends SAS to a set-logic language. So SAS can be considered a general programming language, though it serves largely as database programming language and a language with a wide variety of specialized analytic and graphic procedures. Within the last decade or so, the SAS System has increasingly become a generic platform for elaborate products such as SAS/EM, SAS/Intrnet, and SAS/Access engines.

Attributed-SAS Archives Discussion

Controversy

There has been controversy lately on difference if any on SAS as a language and SAS as a system. While some people believe that SAS exists as a language and cannot be copyrighted by the SAS Institute only. This is because of third party compilers like WPS from World Programming System, GNU DAP (software), and Carolina from Dulles Open and SAS Institute's efforts to be the sole distributor of the SAS language related products.In addition the SAS Institute created a wiki with the condition that any content there is irrevocably and permanently licensed to the SAS Institute. The SAS Institute also hosts and funds some part of the annual SAS User Group Conference with the same condition that all content is irrevocably and permanently licensed to the SAS Institute.

In a recent judgement by High Court in UK, SAS Language was established as a programming language.

In November 2011 Advocate General Bot of the European Union declared that in his opinion that Computer Languages including the language of SAS were not able to be protected by copyright law.

External links