You are on page 1of 19

SCL for Base SAS Programmers

Why and How

Jerry Le Breton

Agenda
This is NOT a tutorial on SCL What is SCL? Why you ought to know How to mix Base SAS and SCL

SAUSAG 16 August 2001

SCL for Base SAS Programmers

What is SCL?
SCL (pre-V7) Screen Control Language SCL (V7+) SAS Component Language For on-line applications (with SAS/AF) Much wider usage for SCL SCL as another facility for the Base SAS programmer

SAUSAG 16 August 2001

SCL for Base SAS Programmers

SCL Features
Supports on-line applications Object oriented language - for code re-use in class libraries Extra coding features and functions
Dynamic arrays SCL Lists Other extra functionality
SAUSAG 16 August 2001 SCL for Base SAS Programmers 4

SCL Invades the Data Step


In 6.12 the SCL I/O functions were included in Base SAS Data Step: data _null_; set logs end=theend; if fileextn='txt' then txt + 1; if theend then put txt=; But
SAUSAG 16 August 2001 SCL for Base SAS Programmers 5

SCL Invades the Data Step


Equivalent SCL code:
dsid=open(logs'); call set(dsid); do while (fetch(dsid)=0); if fileextn='txt' then txt + 1; end; rc = close(dsid);
SAUSAG 16 August 2001 SCL for Base SAS Programmers

(2)

SCL Invades the Data Step

(3)

The previous SCL will run in an SCL program or a Data Step Faster as real SCL because compiled before execution

SAUSAG 16 August 2001

SCL for Base SAS Programmers

SCL Arrays
SCL supports, standard, static arrays
Fixed size array a(10) $20; Fixed type character or numeric

Imagine: hiearchical data on a tape


Rec. type 1: Person details Rec. type 2: Allowance details (0 to many) Need to perform array processing on allowances
SAUSAG 16 August 2001 SCL for Base SAS Programmers 8

SCL Arrays (2)


Data allow1; Infile ... Input ... Allw_type $4. Allw_start ddmmyy8. Allw_end ddmmyy8. ; array types(10) _temporary_ $4; array starts(10) _temporary_ ; array ends(10) _temporary_ ; if <this record for same person> then do; allw_no + 1; types{allw_no} = allw_type; starts{allw_no} = allw_start; ends{allw_no} = allw_end; end; else do; ... extra array processing ... end; 16 August 2001 SCL for Base SAS Programmers

SAUSAG

SCL Arrays

(3)

Static arrays are fixed SCL supports dynamic arrays Special functions define dynamic arrays:
Declare char arrayname(*); Arrayname = makearray(10); rc = redim(arrayname, 20);

Extra array functions that only exist in SCL, e.g: asort - for array sorting copyarray comparearray
SAUSAG 16 August 2001 SCL for Base SAS Programmers 10

SCL Arrays
Equivalent SCL:

(4)

declare char types(*); declare num starts(*); declare num ends(*); ... types = makearray(1); starts = makearray(1); ends = makearray(1); ... fid = fopen(...); do while (fread(fid) = 0); ... if <this record for same person> then do; rc = redim(types, dim(types) + 1); types{dim(types} = allw_type; ... end;
SAUSAG 16 August 2001 SCL for Base SAS Programmers 11

SCL Lists
SCL Lists are really dynamic
elements added (& deleted) without redim elements can be different types elements can be sub-lists elements can have names

SAUSAG 16 August 2001

SCL for Base SAS Programmers

12

SCL Lists (2)


List
N am e
(C )

DOB
2098

(N )

A llo w an c e (L)
123

A llo w an c e
125

(L)

F red S m ith

Type (C) NS Start (C) 14566 End (C) 14602

Type (C) D Start (C) 14710 End (C) 14790

SAUSAG 16 August 2001

SCL for Base SAS Programmers

13

SCL Lists (3)


SCL using lists:
fid = fopen(...); do while (fread(fid) = 0); ... if <new person > then personList = makelist(); ... if <this record for same person> then do; allwDetail = makelist(); rc = insertc(allwDetail, allw_type, -1, 'TYPE'); rc = insertn(allwDetail, allw_start, -1, 'START'); rc = insertn(allwDetail, allw_end, -1, 'END'); rc = insertl(personList, allwDetail,-1,"Allowance"); ... end;
SAUSAG 16 August 2001 SCL for Base SAS Programmers 14

SCL Lists (4)


SCL Lists have special functions
Search, reverse, rotate elements

Lists can be saved as SLIST catalog entries Alternative data structure to SAS data sets - for the right shaped data. Not suitable for large amounts of data - SCL lists are held in memory.
SAUSAG 16 August 2001 SCL for Base SAS Programmers 15

Base SAS & SCL Differences


SCL LENGTH function returns 0 for a null string (instead of 1) SCL SELECT can't cope with multiple values e.g.
SELECT (ITEM); WHEN ('A', 'B') ... /* Not allowed */

IN operator
array list{3} $10 ('cat','bird','dog'); i='dog' in ('cat','bird','dog'); /* i=3 in SCL i=1 in Data Step */ j='dog' in list; /* Only in SCL */
SAUSAG 16 August 2001 SCL for Base SAS Programmers 16

Using SCL with Base SAS


PROC DISPLAY to run an SCL program e.g. proc display c=sasuser.profile.test.scl

SAUSAG 16 August 2001

SCL for Base SAS Programmers

17

Using Base SAS with SCL


Within SCL code, Base SAS is executed in a SUBMIT block E.G.
init: dataset = sashelp.prdsales; SUBMIT continue; proc print data=&dataset; run; ENDSUBMIT; return;
SAUSAG 16 August 2001 SCL for Base SAS Programmers 18

Summary
So why bother with SCL? Extra features: Dynamic arrays SCL Lists Other functions Greater flexibility Can be faster because already compiled ( Job Security?! )

SAUSAG 16 August 2001

SCL for Base SAS Programmers

19

You might also like