Date post: | 07-Apr-2018 |
Category: |
Documents |
Upload: | mahesh-kharate |
View: | 218 times |
Download: | 0 times |
of 19
8/6/2019 0108 Data Step
1/19
1
SCL for Base SAS ProgrammersSCL for Base SAS Programmers
Why and How
Jerry Le Breton
8/6/2019 0108 Data Step
2/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 2
AgendaAgenda
This is NOT a tutorial on SCL
What isSCL?
Why you oughtto know
How to mix BaseSAS and SCL
8/6/2019 0108 Data Step
3/19
8/6/2019 0108 Data Step
4/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 4
SCL FeaturesSCL Features
Supports on-line applications
Object oriented language
- forcode re-use in class libraries
Extra coding features and functions
Dynamic arrays
SCLLists
Otherextra functionality
8/6/2019 0108 Data Step
5/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 5
SCL Invades the Data StepSCL Invades the Data Step
In 6.12 theSCLI/O functions were included in BaseSAS
Data Step:data _null_;
set logs end=theend;
if fileextn='txt' then
txt + 1;if theend then put txt=;
But
8/6/2019 0108 Data Step
6/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 6
SCL Invades the Data Step (2)SCL Invades the Data Step (2)
EquivalentSCLcode:dsid=open(logs');
call set(dsid);do while (fetch(dsid)=0);
if fileextn='txt' then
txt + 1;end;
rc = close(dsid);
8/6/2019 0108 Data Step
7/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 7
SCL Invades the Data Step (3)SCL Invades the Data Step (3)
The previousSCL will run in an SCL program or
a Data Step
Faster as real SCL becausecompiled before
execution
8/6/2019 0108 Data Step
8/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 8
SCL ArraysSCL Arrays
SCLsupports,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
8/6/2019 0108 Data Step
9/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 9
SCL Arrays (2)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 thendo;allw_no + 1;types{allw_no} = allw_type;
starts{allw_no} = allw_start;ends{allw_no} = allw_end;
end;elsedo;... extra array processing ...
end;
8/6/2019 0108 Data Step
10/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 10
SCL Arrays (3)SCL Arrays (3)
Static arrays are fixed
SCLsupports dynamic arrays
Special functions define dynamic arrays:Declare char arrayname(*);
Arrayname = makearray(10);rc = redim(arrayname, 20);
Extra array functionsthat only exist in SCL,e.g: asort - for array sorting copyarray comparearray
8/6/2019 0108 Data Step
11/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 11
SCL Arrays (4)SCL Arrays (4)
EquivalentSCL: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 thendo;rc = redim(types, dim(types) + 1);types{dim(types} = allw_type;...
end;
8/6/2019 0108 Data Step
12/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 12
SCL ListsSCL Lists
SCLLists are really dynamic
elements added (& deleted) without redim
elementscan be differenttypes
elementscan besub-lists
elementscan have names
8/6/2019 0108 Data Step
13/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 13
SCL Lists (2)SCL Lists (2)
ListN am e (C )F red S m ith
D O B (N )2098
A l l o w a n c e (L)123
A l l o wa n c e (L)125
Type (C)
NS
Start (C)
14566End (C)
14602
Type (C)
D
Start (C)
14710End (C)
14790
8/6/2019 0108 Data Step
14/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 14
SCL Lists (3)SCL Lists (3)
SCLusing lists:fid = fopen(...);do while (fread(fid) = 0);...if then
personList = makelist();
...if thendo;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;
8/6/2019 0108 Data Step
15/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 15
SCL Lists (4)SCL Lists (4)
SCLLists havespecial functions
Search, reverse, rotateelements
Listscan besaved asSLISTcatalogentries
Alternative data structureto SAS data sets- for
the rightshaped data.
Notsuitable for large amounts of data - SCL lists
are held in memory.
8/6/2019 0108 Data Step
16/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 16
Base SAS & SCL DifferencesBase SAS & SCL Differences
SCLLENGTH function returns 0 for a null string (instead of1)
SCLSELECT can'tcope 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 */
8/6/2019 0108 Data Step
17/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 17
Using SCL withBase SASUsing SCL withBase SAS
PROCDISPLAYto run an SCL program
e.g. proc display c=sasuser.profile.test.scl
8/6/2019 0108 Data Step
18/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 18
Using Base SAS with SCLUsing Base SAS with SCL
Within SCLcode, BaseSAS isexecuted in a SUBMIT
block
E.G.init:
dataset = sashelp.prdsales;SUBMIT continue;
proc print data=&dataset;run;
ENDSUBMIT;return;
8/6/2019 0108 Data Step
19/19
SAUSAG 16August 2001 SCL for BaseSAS Programmers 19
SummarySummary
So why bother with SCL?
Extra features:
Dynamic arraysSCLListsOther functions
Greater flexibility
Can be faster because already compiled ( Job Security?! )