Download B34S and SAS discussion and examples

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Forecasting wikipedia , lookup

Data assimilation wikipedia , lookup

Transcript
B34S / SAS Quick Start
Version
25 June, 2017
B34S® / SAS® Quick Start
Houston H. Stokes
Abstract:
This document gives a quick overview on how to load data into B34S
and SAS. The objective is to show how the two programs work in a
similar fashion and to allow users to get programs up and running
quickly. In addition links with RATS and SCA are illustrated. Only
the most basic B34S commands are discussed.
Introduction to B34S
The B34S® Data Analysis System is a full featured Econometric Package
developed by Houston H. Stokes at UIC (1972-1997) with the help of others. B34S
is documented in Specifying and Diagnostically Testing Econometric Models, ed.
2, Quorum 1997, by Houston H. Stokes. B34S has strengths in:

An extensive MATRIX language which allows extensive econometric
calculations including nonlinear estimation to be completely coded in a
4th generation language. The MATRIX facility provides nonlinear least
squares capability,, maximization and constrained maximization of a
nonlinear function and nonlinear programming with a nonlinear objective
function and a nonlinear constraints. Real*8, integer and complex*16 data
types are supported.

Limited dependent variable problems (logit, probit, multinominal
logit, ordered probit).

Pooled Data problems (Error Component Models, Dynamic Panel Data Model).

Time Series (ARIMA, Transfer function, VAR, VARMA, VMA, Kalman Filter,
Frequency Decomposition of VAR Model, Spectral Analysis)

Equation specification procedures such as recursive residuals, BLUS
residuals, QR factorization, PC regression and Hinich nonlinearity tests.

Nonlinear Model detection, estimation and forecasting (MARS, PISPLINE
MVNLTEST)

Structural Equations Estimation (2SLS, LIML, 3SLS, I3SLS, constrained
reduced form.)

Markov Analysis.

L1 and MIMIMAX estimation of panel data.

Solution of LP and QP Maximization problems.
B34S has two way links with SCA®, SAS®, SPEAKEASY®, RATS® and can make data
loading files for EXCEL, MATLAB, MINITAB, SHAZAM, LIMDEP and many more systems.
B34S contains a user extendable help facility. B34S menus under the Display
1
B34S / SAS Quick Start
Manager on the PC are developed using the B34S MAKEMENU command which makes them
user extendable. Libraries of templates are supplied for most tasks.
On the PC, B34S contains a data viewer, a data editor, an output and log viewer
and a file editor. The user can designate an editor such as KEDIT, EDIT, NOTEPAD
or KEDITW to use. B34S versions run on IBM CMS, IBM RS/6000, SUN SOLARUS, DOS
and Windows 95/NT. The DOS and Windows 95/NT versions have a graphical front end
(Display Manager) and high resolution graphic capability that includes line
plots, 2 and 3D histograms, bar plots, contour plots and 3D surface plots. The
user has the choice of either supplying the 3D surface in the form of a matrix
or letting B34S determine the surface from three vectors. The B34S graphics
system and front end is based on routines from the Interactor Subroutine
Library. B34S DOS and Windows 95/NT versions are obtainable on-line from
www.uic.edu/~hhstokes/hhstokes/b34s.htm
provided the user has the appropriate b34s.ini authorization file. This short
paper introduces the reader to the B34S system and describes how B34S relates to
SAS. No advanced B34S commands are discussed although a complete list of B34S
commands in provided.
Overview of SAS and B34S
B34S and SAS are complementary systems. Both programs can call each other.
The SAS system is extensively documented in a large number of publications. That
is both a strength and weakness. Important SAS documentation includes:
Basic System:
SAS® Language and Procedures, Introduction Version 6
ISBN 1-55544-410-5
SAS® Language: Reference, Version 6 ISBN 1-55544-381-8
SAS® Procedures Guide, Version 6 Ed. 3 ISBN 1-55544-378-8
SAS® Language and Procedures Usage 1, Version 6 ISBN 1-55544-371-0
SAS® Language and Procedures Usage 2, Version 6 ISBN 1-55544-445-8
SAS/STAT®
SAS/STAT® User’s Guide, Version 6 Volume 1 4th ed.
ISBN 1-55544-376-1
SAS/STAT® User’s Guide, Version 6 Volume 2 4th ed.
ISBN 1-55544-376-1
SAS/ETS®
SAS/ETS® User’s Guide, Version 6, Ed. 2, ISBN 1-55544-554-3
SAS/ETS® Software Applications Guide 1, Version 6,
ISBN 1-55544-480-6
SAS/ETS® Software Applications Guide 2, Version 6,
ISBN 1-55544-549-7
2
B34S / SAS Quick Start
SAS/GRAPH®
SAS/GRAPH® Software Usage, Version 6, ISBN 1-55544-421-0
SAS/GRAPH® Software Reference, Volume 1, ISBN 1-555444-379-6
SAS/GRAPH® Software Reference, Volume 1, ISBN 1-555444-379-6
Macro Facility
SAS® Guide to Macro Processing, Version 6 ed. 2 ISBN 1-55544-382-6
Serious SAS users should obtain the five manuals under the basic system and the
two manuals under STAT as a minimum. The three manuals under ETS are needed for
econometrics. Most users will not need the graphics manuals or the SAS Macro
Facility manuals. The usage guides are most helpful.
B34S is documented in Specifying and Diagnostically Testing Econometric
Models by Houston H. Stokes, Second Edition Quorum Books 1997. Specific help is
available on-line using the B34S HELP facility. The B34S help facility on the PC
is available under the B34S Display Manger. The help facility is also available
with the command line. For example the command:
b34sexec help=manual newpage bottompn makeindex$ b34srun$
will place the complete manual in the b34s.log file, will provide an index and
will put in page numbers. This document can be printed. Specific command such as
PROBIT can be obtained by:
b34sexec help=probit$ b34srun$
The B34S user has the ability to add to the help files and create other help
commands if desired. Table 1 lists the current B34S commands and their
functions:
3
B34S / SAS Quick Start
Table One B34S commands
___________________________________________________
Command
HELP
OPTIONS
REGRESSION
LIST
PLOT
PROBIT
TOBIT
LOGLIN
ECOMP
AUTOC
RR
QR
DATA
MPROBIT
MLOGLIN
SIMEQ
TRANSPROB
BJIDEN
BJEST
BTIDEN
BTEST
NONLIN
VARFREQ
PGMCALL
POLYSOLV
DTASSM
OPTCONTROL
CALL
KFILTER
SOURCE
SCAINPUT
FORECAST
MARS
PISPLINE
GENMOD
HRGRAPHICS
SORT
SPECTRAL
MAKEMENU
DMF
MVNLTEST
CITIBASE
READVBYV
REG
MERGE
TRANSPOSE
DESCRIBE
ROBUST
FREQ
LPMAX
EXPAND
MATRIX
SCAIO
Description
Provide help, generate on-line manual.
Set B34S run time options.
OLS and GLS estimation. BLUS and RA analysis.
Display data in B34S data file.
Plot and graph series in B34S data file.
Probit analysis on (0-1) dependent variables.
Tobit analysis on truncated dependent variables.
Logit analysis on up to 4 equations at once.
Error component analysis.
Autocorrelation and cross-correlation analysis.
Recursive residual analysis.
QR factorization & principal comp. approach to OLS
Load Data into B34S without SAS/B34S interface.
Multinomial probit analysis.
Multinomial logit analysis.
2SLS, LIML, 3SLS, I3SLS, FIML, SUR estimation.
Estimate Markov Probability Model.
Box-Jenkins Identification. Spectral Analysis.
Box-Jenkins ARIMA, transfer function estimation.
Identification of VAR, VARMA models.
Estimation of VAR, VARMA, VMA models.
Estimation of user-specified nonlinear models.
Spectral decomposition of VAR models.
Call SAS, SPEAKEASY, SCA, MATLAB, LIMDEP, RATS, MINITAB
Solution of polynomials.
Data manipulation utilities.
Optimal control analysis.
Call user procedure.
Estimate State Space Model.
B34S FORTRAN source manager.
B34S/SCA Input option.
Automatic VAR Forecasting Model Development.
Multivariate Adaptive Regression Splines.
PI Method of Fitting an underlying smooth function.
Generate Data sets with given covariance structure.
High Resolution Graphics.
Sort data.
Spectral analysis.
Make user menus to input commands to B34S.
Data Management Facility.
Multivariate tests for nonlinearity.
Load Citibase data into B34S using RATS.
Reads data variable by variable.
General OLS Command
Merge files.
Transpose the data matrix.
Describes series. Useful to see missing values.
Robust (L1 & MINIMAX) estimation.
Frequency and cross tabulations.
Solution of LP maximization problems.
Expand weighted data
Full 4th generation programming language
Read and write SCA® variable by variable data files
_______________________________________________________________________
4
B34S / SAS Quick Start
Basic Program structure
Both the SAS and B34S command language is based on paragraphs. For B34S,
each paragraph contains sentences ending with either $ or ;. The first sentence
in each paragraph begins with B34SEXEC. The last sentence in the paragraph ends
with the sentence B34SRUN$ or B34SEEND$. Keywords can be upper or lower case. As
an example we load two series on age and values of cars in B34S and run a
regression. A list of the data is also made.
b34sexec data$
input age value$
datacards$
1 1995
3 875
6 695
10 345
5 595
2 1795
b34sreturn$
b34srun$
b34sexec list$ b34srun$
b34sexec reg$ model value = age$
b34srun$
If the above listed commands are saved as test.b34, the unix command
b34s test
will produce a file test.out containing the results of the commands run and a
file test.log which will contain any errors. Note that this b34s command file
contains calls to three procedures: DATA, LIST, REG.
The SAS command language is also based on paragraphs. Each paragraph in
SAS contains sentences ending with ;. The first sentence in the paragraph begins
with the key word DATA or PROC. The last sentence in the paragraph must be RUN;.
The same problem as run with b34s above in SAS would be
data test;
input age value;
cards;
1 1995
3 875
6 695
10 345
5 595
2 1795
;
run;
proc means; run;
proc print; run;
proc reg; model value = age;
run;
The B34S DATA and READVBYV commands automatically give the means. This is not
true in SAS. In the SAS example we had to make a call to PROC MEANS. In both
5
B34S / SAS Quick Start
B34S and SAS, data is read by observation. If the data is available only by
variable, in B34S data can be read using the READVBYV command. If changes are
desired in the data, the B34S DATA command can be used to transform the data. A
simple example follows where three series are read with four observations per
series:
b34sexec readvbyv noob=4$
input var=x$
input var=y$
input var=z$
datacards$
1 2 3 4
66.7 55.5 43.6 33.8
88.8 77.7 33.1 99.2
b34sreturn$
b34srun$
/$ Multiply x by y and put in xtimesy
b34sexec data set$
build xtimesy$
gen xtimesy=x*y$
b34seend$
This sample has been annotated with the generalized b34s comment which begins
with /$ in column 1-2. The generalized comment is useful in “turning off” code.
If possible, data should be loaded by observation rather than by variable. The
above job illustrates the b34s data paragraph. Note that new variables have to
be listed on the BUILD sentence before they can be recognized by the GEN
sentence. This design was developed to reduce the possibility of errors where
small spelling errors are not noticed and the data is not built correctly. In
SAS data is built with the DATA paragraph. As an example consider the SAS
commands
data test;
input age value;
valuesq=value*value;
cards;
1 1995
3 875
6 695
10 345
5 595
2 1795
;
run;
Datasets
SAS has the ability of having multiple datasets current at the same time.
The below listed code contains two SAS datasets TEST1 and TEST2. Dataset TEST1
contains two series, TEST2 has three series.
data test1;
input age value;
cards;
1 1995
3 875
6
B34S / SAS Quick Start
6 695
10 345
5 595
2 1795
;
run;
data test2;
set;
agesq=age*age$
run;
proc means data=test1; run;
proc means data=test2; run;
SAS will produce permanent datasets on disk. Assume data on X and Y are in
a file SASDATA on a PC. The below listed job will load the DATA and make a SAS
dataset jj.sd2 in subdirectory C:\junk
libname test 'c:\junk' ;
data test.jj;
infile 'c:\junk\sasdata';
input x y;
proc means;
This can be read with the SAS job
libname test 'c:\junk';
proc print data=test.jj;
In B34S there is only one dataset in existence at one time. However
the data in the current dataset can be modified. For example
b34sexec data$
input age value$
datacards$
1 1995
3 875
6 695
10 345
5 595
2 1795
b34sreturn$
b34srun$
b34sexec data set$
build agesq$
gen agesq=age*age$
b34srun$
To read B34S data from a file such as c:\mydir\age.dat and build variables,
b34sexec data file=('c:\mydir\age.dat')$
input age value$
b34srun$
b34sexec data set$
build agesq$
gen agesq=age*age$
b34srun;
7
B34S / SAS Quick Start
b34sexec reg$ model value=age agesq$
b34srun$
The permanent form of the b34s dataset is a DMF file. There are two types,
formatted and unformatted. Formatted DMF files can be moved across machines (PC
to unix for example), although they load slower and are larger in size than an
unformatted dmf. The b34s commands to create a formatted dmf file are:
b34sexec options open('testdmf.dmf') disp=unknown
unit=60 $b34srun$
b34sexec options clean(60)$ b34srun$
/$ Tests Create
b34sexec options include('c:\b34slm\gas.b34')$
b34srun$
b34sexec dmf inunit=60 outfmt=formatted dmfmember=one$
create disp=rewind heading('Gas data test case')
comment('Loads Gas data') $
b34srun$
This job assumes there was a file gas.b34 that loaded the gas data. The dmf file
testdmf.dmf can be read with the command:
b34sexec data filef=dmf file('testdmf.dmf')$
b34srun$
B34s is very forgiving on command syntax. For example filef(dmf) is the same as
filef=dmf. If an INPUT sentence is used while reading from a DMF, a subset of
the variables can be loaded. The DMF file can be created on the PC directly from
the b34s Display Manager from the menu window.
Moving Datasets Across Different Computers
A SAS command file such as test.sas or a b34s command file such as
test.b34 can be edited with an editor or moved freely from one type of computer
to another. An unformatted B34S DMF file cannot be moved without conversion to a
formatted DMF file. The PC B34S has a sample jobs CONVDMF1 and CONVDMF2 under
the TASKS command than can be used to convert unformatted to formatted and
formatted to unformatted DMF files. Once the B34S DMF file is converted to a
formatted DMF file, it can be moved between machines using FTP as a text file.
It can even be looked at with an editor, although the format cannot be changed.
The control setup for CONVDMF1 is:
/$ Converts a DMF file from unformatted to formatted
/$ User needs only to change b34slet for oldfile and newfile
/$ Be sure to use the form "' somename '"
/$
/$ This feature is useful in labels and or names in a DMF file
/$ need to be changed.
/$
/$ Job uses convention that *.dmf is an unformatted DMF file and
/$
*.aaa is a formatted DMF file
/$
%b34slet oldfile = "'oldfile.dmf'"$
%b34slet newfile = "'newfile.aaa'"$
b34sexec options open(%b34seval(&oldfile)) unit=60 disp=old$
b34srun$
8
B34S / SAS Quick Start
b34sexec options open(%b34seval(&newfile)) unit=61 disp=unknown$
b34srun$
b34sexec options clean(61)$ b34srun$
b34sexec dmf unit=60 infmt=unformatted outunit=61 outfmt=formatted$
convertuf$ b34srun$
/$ Optionally browse new file.
b34sexec dmf unit=61 infmt=formatted$ browse listnames$ b34srun$
To run this job the used needs only to set OLDFILE and NEWFILE names. The same
thing goes for the conversion the other way.
The CONVDMF2 file is:
/$ Converts a DMF file from formatted to unformatted
/$ User needs only to change b34slet for oldfile and newfile
/$ Be sure to use the form "' somename '"
/$
/$ Job uses convention that *.dmf is an unformatted DMF file and
/$
*.aaa is a formatted DMF file
/$
%b34slet oldfile = "'oldfile.aaa'"$
%b34slet newfile = "'newfile.dmf'"$
b34sexec options open(%b34seval(&oldfile)) unit=60 disp=old$
b34srun$
b34sexec options open(%b34seval(&newfile)) form=unformatted
unit=61 disp=unknown$ b34srun$
b34sexec options clean(61)$ b34srun$
b34sexec dmf unit=60 infmt=formatted outunit=61 outfmt=unformatted$
convertfu$ b34srun$
/$ Optionally browse new file.
b34sexec dmf unit=61 infmt=unformatted$ browse listnames$ b34srun$
SAS has a similar facility except that the export file has to be moved as
a binary file. The next four SAS jobs illustrate the SAS export facility on a
PC. Control file one loads the GAS data into a SAS file c:\junk\funny.sd2. Not
all observations are shown.
libname test 'c:\junk';
data test.funny;
input
TIME
GASIN
GASOUT
CONSTANT
;
label GASIN
=
"Input gas rate in cu. ft / min
label GASOUT
=
"Percent CO2 in outlet gas
cards;
1.000 -0.10900000 53.800 1.00
2.000 0.00000000 53.600 1.00
3.000 0.17800000 53.500 1.00
4.000 0.33900000 53.500 1.00
5.000 0.37300000 53.400 1.00
6.000 0.44100000 53.100 1.00
7.000 0.46100000 52.700 1.00
9
";
";
B34S / SAS Quick Start
8.000 0.34800000
. . . . . . . . .
295.0 -0.18200000
296.0 -0.26200000
52.400 1.00
. . . . . . . .
57.300 1.00
57.000 1.00
;
PROC MEANS;
The next job reads the SAS internal SD2 file c:\junk\funny.sd2 and calculates
means.
libname test 'c:\junk';
proc means data=test.funny; run;
The next job will take the SAS SD2 file and make an export file
c:\junk\export.dat. This file can be moved as a binary file to the new computer.
libname misc 'c:\junk';
libname alldata xport 'c:\junk\export.dat';
proc copy in=misc out=alldata memtype=data; run;
The final job will rebuild the SD2 SAS file c:\junk\funny.sd2 from the SAS
export file c:\junk\export.dat. These examples were tested using PC SAS version
6.12.
* The name here is the pc or unix directory ;
libname misc 'c:\junk' ;
* The dataset here indicates the export file name ;
libname alldata xport 'c:\junk\export.dat';
proc copy in=alldata out=misc; run;
Data Building and Loading Examples using B34S
b34sexec data$
input x y z$
datacards$
1 11 111
2 22 222
3 33 333
4 44 444
5 55 555
b34sreturn$
b34seend$
The above example could be written as
b34sexec data$
input x y z$
datacards$
1 11 111 2 22 222 3 33 333 4 44 444 5 55 555
10
B34S / SAS Quick Start
b34sreturn$
b34seend$
since if NOOB is NOT set the default reading option is FILEF=@@.
If NOOB is set explicitly, FILEF=FREE by default. This will read
Faster but will not read character data.
b34sexec data noob=5$
input x y z$
datacards$
1 11 111
2 22 222
3 33 333
4 44 444
5 55 555
b34sreturn$
b34seend$
If NOOB is set and the data is all on one row or broken up, then
FILEF=@@ must be set.
b34sexec data noob=5 filef=@@$
input x y z$
datacards$
1 11 111 2 22 222 3 33 333 4 44 444 5 55 555
b34sreturn$
b34seend$
It is to be noted that FILEF=@@ is the most flexible reading format
but it also is the slowest. FILEF=FREE is faster, but is slower than
FILEF=FIXED. FILEF=DP is the fastest.
The next example shows data building and a regression being run.
b34sexec data noob=5$
input x1 y1 z $
build sumy1z $
gen sumy1z = y1+z$
datacards$
11 22 33
33 44 33
333 3.0 666
22 33 11
11.2 33.4 22.2
b34sreturn$
b34seend$
b34sexec regression$
model x1 = sumy1z$
b34srun$
/$
/$ we reload the data and build some more data.
/$ note that prior step ends with b34srun$, not b34seend$.
/$ optional labels (max of 40 cols) have been supplied.
/$
b34sexec data set$
build x1ty1 x1py1 xx$
11
B34S / SAS Quick Start
label x1ty1 = 'x1 * y1
'$
label x1py1 = 'x1 + y1
'$
label xx
= '(x1**3)/(sin(x1)+(2.0*cos(x1/y1)))'$
gen x1ty1
= x1*y1$
gen x1py1
= x1+y1$
gen xx
= (x1**3)/(sin(x1)+(2.0*cos(x1/y1)))$
b34seend$
/$
/$ we list the data
/$
b34sexec list$ b34srun$
Data loading from a file on PC
Assume X1,...,X6 are on a file MYDATA.DAT. The below listed statements
will load the series and perform a regression after building data. Since
there is no FILEF= parameter, @@ is assumed. If more than one
observation is placed on one card, use FILEF=@@.
b34sexec options open('mydata.dat')
unit=10 disp=old$ b34seend$
b34sexec data unit(10)$
input x1 x2 x3 x4 x4 x6$ build x1sq x1tx2$
gen x1sq =x1*x1$
gen x1tx2 =x1*x2$
b34seend$
b34sexec regression$
model x6=x1 x2 x3 x4 x5 x1sq $ b34seend$
The same job can be coded with the file statement as:
b34sexec data file('mydata.dat')$
input x1 x2 x3 x4 x4 x6$
build x1sq x1tx2$
gen x1sq =x1*x1$
gen x1tx2 =x1*x2$
b34seend$
b34sexec regression$
model x6=x1 x2 x3 x4 x5 x1sq $ b34seend$
Assuming mydata.dmf was a dmffile with multiple members, if member
CRIME was to be loaded:
b34sexec data filef=dmf file(‘c:\mysd\mydata.dmf’)
dmfmember(crime)$
input x y z$
b34seend$
If MYDATA.DMF contained 80 series and the user wanted to load all 80
series without using an INPUT statement, the correct setup would be
just to omit the IMPUT statement. If the DMF file contained more than
98 series and the INPUT statement was omitted, only the first 98 series
would be read.
The IBEGIN and IEND options on the DATA sentence control whether all
observations from the DMF file are read. Assume that the MYDATA.DMF file
12
B34S / SAS Quick Start
contains 2000 observations but the user wants to load only from
observation 23 to observation 1023. The correct commands would be
b34sexec options open('c:\mysd\mydata.dmf') unit(60)$ b34seend$
b34sexec data filef=dmf unit(60) dmfmember(crime)
ibegin=23 iend=1023$
input x y z$
b34seend$
B34S MATRIX Command
The power of the MATRIX command is illustrated using a few jobs.
Example # 1 shows OLS Modeling using the the commands REG, ROBUST and the
MATRIX Command Language. Note the way that lags are specified.
/$ Illustrates OLS Capability under Matrix Command
b34sexec options ginclude('b34sdata.mac')
member(gas); b34srun;
b34sexec reg;
model gasout=gasin; b34srun;
b34sexec robust; model gasout=gasin; b34srun;
b34sexec reg; model gasout=gasin{0 to 1} gasout{1};
b34srun;
b34sexec matrix;
call loaddata;
call olsq(gasout gasin:print :diag);
call graph(%res
:heading 'Residual');
call graph(%y %yhat :heading 'Fitted and Actual');
call olsq(gasout gasin{0 to 1} gasout{1} :print);
call names;
call print('Model of ',%yvar);
call tabulate(%names,%lag,%coef,%se,%t);
call tabulate(gasout,%y,%yhat,%res);
call graph(%res,:heading 'Residuals');
call graph(%y,%yhat :heading 'Fitted and Actual Values.');
maxi=24;
do i=1,maxi;
call olsq(gasout gasin{0 to i} gasout{1 to i}:print);
call print(acf(%res,24));
enddo;
b34srun;
13
B34S / SAS Quick Start
Example # 2 shows OLS done three ways:
b34sexec options ginclude('gas.b34');
b34srun;
/$
/$ OLS is done three ways: 1. with reg
/$
2. with matrix
/$
3. with olsq
/$
b34sexec reg; model gasout=gasin; b34srun;
b34sexec matrix;
call loaddata;
x=matrix(norows(gasin),2:);
x(,1)=vfam(gasin);
call setcol(x,2,1.0);
xpx=transpose(x)*x;
call names;
beta=vfam((1./xpx)*transpose(x)*mfam(gasout));
call print(xpx,beta);
fgasout=vfam(x*mfam(beta));
resid=vfam(gasout)-vfam(fgasout);
call names; ss=resid*resid;
sigma=ss/dfloat(norows(resid)-2);
se=dsqrt(diag(sigma*(1.0/xpx))); t=afam(beta)/afam(se);
n=namelist(gasin,const);
call print('Gasout = a + b*Gasin','RSS',ss);
call tabulate(n,beta,se,t);
call tabulate(gasout fgasout resid);
call graph(resid:heading 'Residuals from Gas Data');
call olsq(gasout,gasin :print);
call tabulate(%y,%yhat,%res);
b34srun;
B34S Display Manager System
The B34S Display Manager, available currently only on the PC
versions of B34S, allows the user to control and modify the execution of
the B34S program from a windows type environment. B34S versions 7.xx and beyond
running on DOS, Windows 95 and Windows NT use the Interactor Windows and Graphic
library. The Display Manager provides a way to select the file to run, view the
b34s.log and b34s.out file and make changes to the command file. The B34S has a
built in editor or allows the user to call an editor such as KEDIT, KEDITW, EDIT
or NOTEPAD. The B34S GRAPHICS and MENU Display Manager commands allow access to
a number of menus that provide fill-in blanks to perform a number of simple
tasks. The usual way the Display Manager is run is to edit and submit b34s
command files. Once the command files are run the log and out files can be
viewed, edited or renamed and saved. The Display Manager provides access to
libraries of b34s command file code which can be modified and rerun. The MENU
and GRAPHICS commands can either be used to enter commands from menus or to
build command files which can be saved in the B34S Program Buffer (under the
Tasks menu). The PC file c:\b34slm\ratspgm.mac contains a number of B34S/RATS
jobs that are useful in building command files than will pass daat to RATS386.
The file c:\b34slm\b34stest.mac provides a number of test jobs that illustrate
14
B34S / SAS Quick Start
most of the B34S commands. The file c:\b34slm\b34sdata.mac contains a large
number of useful datasets. Other files are c:\b34slm\berndt.mac which contains a
large number of famous datasets and c:\b34slm\greene.mac which contains all the
datasets from Econometric Analysis by William Greene Third Edition 1997. All
files ending in .MAC are mac files. They can be read with b34s commands such as:
b34sexec options include(‘c:\b34slm\b34sdata.mac’)
member(gas)$ b34srun$
B34S mac files have the structure
==name1
.............
.............
==
==name2
.............
.............
==
and are designed to be built by users with editors such as kedit.
SAS version 6.12 provides a facility where the user can edit and submit
SAS jobs. SAS has no preprogrammed menu facility. Both B34S and SAS have a Macro
Capability whereby it is possible to have a programming language to write code
that in turn is executed. These advanced features are not discussed here. In SAS
the AF facility provides the user the capability of generating menus. In B34S
the MAKMENU command provides a similar capability. Most users never have to deal
with programming these advanced features in either system. All the menus under
the MENU or GRAHICS commands of the Display Manager are actually B34S MAKEMENU
jobs. This way the B34S menus are not a part of the b34s program. They are b34s
command files that execute and in turn generate more b34s commands. The major
advantage of this design is that the user can build and modify b34s menus and
“customize” the software without having to change the B34S program itself.
Missing Data
Both B34S and SAS have missing data capability. SAS will read . as a
missing value and all SAS procedures will ignore this value. The way that SAS
has been programmed has caused some confusion. Assume the following
SAS job
data test1;
input age value make;
cards;
1 1995 0
3 875 1
6 695 0
10 345 0
5 595 1
2 1795 0
. 1900 1
8 785
.
;
run;
proc reg;
model value = age;
15
B34S / SAS Quick Start
model value = make;
run;
proc reg;
model value = age;
run;
proc reg;
model value = make;
run;
If would appear that the user has run the same two regression two times.
However, this is not the case. In the first call to proc reg; SAS will drop two
observations since if both value and make are not missing, then two observations
must be dropped. The second and third call to proc reg will have one more
observation since that is the maximum number possible. This “feature” of SAS
makes it difficult to compare regressions when there are missing data unless all
regression are run at one time or the data file is explicitly built to remove
missing data.
B34S supports missing values in a different manner. If on the B34S DATA
paragraph the parameter FILEF=@@ is used, then B34S will interpret na NA and .
as missing values for non-character data. The B34S missing value code will be
assigned to this series for that observation. The MISSING=r parameter on the
B34S OPTIONS paragraph allows the user to select missing values. If the B34S
OPTIONS option KEEPMISS is in effect (the default) these values are left in the
dataset unless explicitly deleted using GEN statements under the DATA paragraph.
If DROPMISS is in effect, then missing data which are read will have the
observation automatically dropped. If this is not desired, then the GEN
statement
GEN
X=DIFMISSING(X)$
can be used to selectively drop observations where X is missing.
An existing dataset containing missing data can be automatically
adjusted to remove observations containing missing data with the
statements:
B34SEXEC OPTIONS DROPMISS$ B34SRUN$
B34SEXEC DATA SET$ B34SRUN$
An alternative is to set DROPMISS on the DATA sentence. Either way,
DROPMISS will be in effect until explicitly changed back to the default
with the KEEPMISS command.
If missing data is left in the dataset, then the current release of
B34S allows this data to be passed to the B34S procedures. While this
may be desired with such procedures as HRGRAPHICS to graphically tell the
location of missing data, the REGRESSION command will give highly misleading
results if missing data are passed. Users should inspect means and maximum and
minimum values of series to detect whether missing data is in the dataset.
The FILEF=@@ option on the DATA paragraph is slower than the
FILEF=FREE option. Hence setting READMISS or using FILEF=@@ explicitly
is slower. Users should inspect their data closely to make sure that
the data that is in the sample is what was desired.
If MAXLAG is set on the DATA paragraph and in addition a GEN
16
B34S / SAS Quick Start
statement such as
GEN D=DIFMISSING(X)$
is found, then the data file will be adjusted BEFORE any MAXLAG takes
effect. In other words, before MAXLAG advances the dataset, DIFMISSING
completely removes the observation from the dataset. MAXLAG is intended
to allow the user control over lags. DIFMISSING allows cross section
users to adjust the dataset for missing data points. Users must use the
LIST paragraph to inspect the data to make sure that file is what is
desired. Under the Display Manager data can be viewed or edited.
The MISSING parameter on the OPTIONS sets the default missing value.
The absolute value of any value supplied will be used. It is recommended
that the default of .1D+32 be used.
The above discussion applies only to non character data. The missing
value codes . NA and na are kept in the dataset for character data
since NA or na might be data that is valid. If the user wants to remove
these values, explicit GEN statements should be used. The below listed
sample job illustrates how this could be done.
/$ Here dropmiss will not remove 'missing' character data
b34sexec data dropmiss$ input x z$ character x z$
datacards$
11
a7
2.
a8
.
a9
na
a0
NA
a99
b34sreturn$
b34seend$
b34sexec list$ b34seend$
b34sexec data set$ build test$ character test$
gen test ='OK'$
gen if(x.eq.'.' )test='foundit'$
gen if(x.eq.'NA')test='foundit'$
gen if(x.eq.'na')test='foundit'$
b34seend$
b34sexec list$ b34seend$
b34sexec data set$
gen if(test.eq.'foundit')test=difmissing(missing())$
b34seend$
b34sexec list$ b34seend$
The above job illustrates IF statements and character data in B34S.
Another alternative would be to directly assign the missing value code
to the character variable and use another data step to remove this
value. The disadvantage of this approach is that when listing character
data where the missing value code is explicitly entered, display
problems can occur is the LIST command is used.
If the data set read contains missing values coded with a value that is
not the B34S missing value code, then the parameter RMISSING on the DATA
paragraph can be used to automatically recode the values. It is
important that all significant digits be used. The below listed example
shows how this might be done. The coded missing value of -9999 will be
17
B34S / SAS Quick Start
automatically replaced with the B34S missing value code.
B34SEXEC DATA RMISSING=-9999$
INPUT X Y$
DATACARDS$
11 22
33 -9999
44 55
B34SRETURN$
B34SEEND$
Problem. Assume that the user has a dataset that contains some
variables that are missing on some period and some in other periods. The
goal is to use the data that is available in a regression. The solution
is:
- 1. Load the data in B34S with KEEPMISS in effect.
- 2. Make a B34S DMF file.
- 3. Load from the DMF just the series that are desired.
The above logic gets around the problem with missing data that occurs with the
way SAS handles the problem what was discussed earlier. What must be stressed is
that there is no really good way to handle the problem. The important thing is
to get the desired results of the analysis.
Use of the B34S DMF file to handle missing data is illustrated with the sample
job shown next:
/$ Shows how to load data you want if missing values
b34sexec data keepmiss$
input x y z$
datacards$
1
2 .
11 22 .
11 22 33
. 44 55
. 55 66
b34sreturn$
b34srun$
b34sexec list$ b34srun$
b34sexec options open('test.dmf') unit=60
form=(unformatted) disp=unknown $
b34srun$
b34sexec dmf dmfmember(checkpoint) outfmt=unformatted$
create disp=rewind$
b34srun$
/$ Run b34s with part of dataset
b34sexec data filef=dmf file('test.dmf') dropmiss$
input x y$
b34srun$
b34sexec list$ b34srun$
/$ Run with the other part
b34sexec data filef=dmf file('test.dmf') dropmiss$
input y z$
b34srun$
b34sexec list$ b34srun$
18
B34S / SAS Quick Start
/$ Run with both parts
b34sexec data filef=dmf file('test.dmf') dropmiss$
input x y z$
b34srun$
b34sexec list$ b34srun$
The first DATA step loads all series keeping the missing data. This data
is saved in the file 'test.dmf' with the DMF step. The next two DATA
steps only load the data than is needed. The final data step runs where all
series are loaded and not missing.
The B34S DMF facility allows the user to selectively load data as
needed.
The B34S DESCRIBE command can be used to determine the extent of
missing data in a file. The commands
b34sexec describe$ b34seend$
will list means, variances, medians, average deviation, skewness and
kurtosis for all series where there are > 2 observations without
missing data.
The command
b34sexec describe$
group(x,y,z)$
group(x,y)$
b34seend$
indicates for how many observations x, y, and z are not missing
and for how many observations x and y are not missing. This command gives the
user some idea of where the data is missing and what overlaps there are in the
data. To use this command effectively, the KEEPMISS option has to be in effect
on the b34s a loading step.
Lags in SAS and B34S
The B34S REG and ROBUST commands provide a quick way to enter lags and
test model dynamic specification. For example the code
b34sexec options include(‘c:\b34slm\gas.b34’)$
b34srun$
b34sexec reg$
model gasout = gasin{0 to 60} gasout{1 to 60}$
bispec iturno iauto$
b34srun$
estimates a model with 60 lags on gasout and gasin and does Hinich nonlinearity
tests. Other than the B34S REG and ROBUST commands, other B34S commands are not
designed to automatically exclude data that is missing. If there are missing
data in the B34S dataset, the B34S DATA command or the B34S EXPAND command with
the appropriate weight variable must be used to remove the data points that are
not desired. In SAS in order to run proc reg with lags would require the user to
19
B34S / SAS Quick Start
build 60 lags of gasout and 60 lags of gasin in the SAS datastep. The best way
to proceed in SAS would be to use PROC ARIMA which is harder to setup.
SAS and B34S DATA Commands
The SAS DATA command is much more powerful and comprehensive than the B34S
DATA step. Both B34S and SAS share a number of similar features.
If statements in B34S are:
gen
gen
gen
gen
gen
if(x .eq. y)kk=1.0$
if(y .lt. k)then$
v=1.0$
q=2.0$
endif$
In SAS the code would be
if x = y then kk=1.0;
if y < K then;
v=1.0;
q=2.0;
endif;
The SAS datastep allows the user to easily subset the data and to build almost
any structure. A large number of data building commands are available. Many
people think that the data handling capability of SAS is the most valuable
feature of the system. The developer of B34S suggests that SAS be used to build
and maintain any datasets where there are over 98 variables or where extensive
data building is needed. Once the data is built, SAS can be set to call B34S for
advanced processing.
SAS and B34S Commands
A number of commands in B34S and SAS work almost if not the same.
In SAS
PROC SORT;
BY TEST;
RUN;
in B34S is
B34SEXEC SORT;
BY TEST;
B34SRUN$
Not all SAS/B34S commands work the same. SAS is a massive program built by a
major company. B34S is a much smaller program built by one person with the help
of others. B34S gets a great deal of its power by allowing links to other
software systems such that as far as the B34S user is concerned, the programs
are linked. There are a large number of procedures in either program where there
is not a close substitute in the other program. For example the B34S MARS,
PISPLINE, BTEST, MPROBIT, RR, VARFREQ, MLOGLIN and ROBUST commands do not have
close, or in most cases, any substitutes in SAS. On the SAS side, PROC IML,
20
B34S / SAS Quick Start
PDLREG, CATMOD, FSP and a large number of other commands do not have B34S
variants. While the B34S FREQ command will work similar to SAS, the SAS FREQ
command is much more comprehensive. Table Two Lists the Command in SAS and a
close command in B34S.
Table Two SAS and B34S Commands
________________________________________________________________________
SAS Command
B34S Command
________________________________________________________________________
SORT
SORT
FREQ
FREQ
PRINT
LIST
MEANS
DESCRIBE (plus datastep)
REG
REG, ROBUST, REGRESSION
STATESPACE
KFILTER
AUTOREG
REGRESSION
SYSLIN
SIMEQ
ARIMA
BJIDEN, BJEST
SPECTRA
SPECTRAL
AF
MAKEMENU
PLOT
PLOT
GRAPH
HRGRAPHICS
IML
MATRIX
________________________________________________________________________
Advanced Capabilities
B34S provides two way communications with RATS, MATLAB, SCA, SPEAKEASY and
other software. In this mode of operation the b34s user can pass vectors of data
and commands to the program and return results to the b34s output file. The file
ratspgm.mac contains a number of sample setups. The below listed B34S commands
show how an ARCH model is estimated in RATS and the results returned to B34S.
The code is set to run on unix and windows 98/nt without change.
b34sexec options ginclude('gas.b34')$ b34srun$
b34sexec options open('rats.dat') unit(28) disp=unknown$ b34srun$
b34sexec options open('rats.in') unit(29) disp=unknown$ b34srun$
b34sexec options clean(28)$ b34srun$
b34sexec options clean(29)$ b34srun$
b34sexec pgmcall$
rats passasts
pcomments('* ',
'* Data passed from b34s(r) system to rats',
'* ') $
pgmcards$
*
set seriesn = gasout
compute iter = 100,isiter=100
*
* arch with ma
*
* see page 5-31 rats manual
*
smpl(series=seriesn)
set v = 1.0
set ra = 0.0
nonlin b0 b1 b2 mu1
a0 a1
21
B34S / SAS Quick Start
frml regresid = seriesn - b0 - b1*seriesn{1}-b2*seriesn{2} $
+ mu1*ra{1}
* note: to add more series on the right place added lines before
*
+ mu1 * ra{1} line
frml archvar = a0+a1*regresid(t-1)**2
frml archlogl = (v=archvar(t)),(ra(t)=regresid(t)), $
-.5*(log(v)+ra(t)**2/v)
linreg seriesn
# constant seriesn{1} seriesn{2}
compute b0=%beta(1),b1=%beta(2),b2=%beta(3)
compute a0=%seesq, a1=.05, mu1=0.0
* maximize(method=simplex,recursive,iterations=iter) archlogl 3 *
nlpar(subiterations=isiter)
maximize(method=bhhh,recursive,iterations=iter) archlogl 3 *
smpl(series=ra)
statistics ra
set rssa = ra(t)*ra(t)
statistics rssa
smpl(series=rssa)
compute sumsqra = %sum(rssa)
display 'sum of squares of ra' sumsqra
*
b34sreturn$
b34srun$
b34sexec options close(28)$ b34srun$
b34sexec options close(29)$ b34srun$
b34sexec options dodos('rats386 rats.in,rats.out')
dounix('rats rats.in rats.out')$ b34srun$
b34sexec options npageout
writeout('output from rats',' ',' ')
copyfout('rats.out')
dodos('erase rats.in','erase rats.out','erase rats.dat')
dounix('rm rats.in','rm rats.out','rm rats.dat') $
b34srun$
B34S communicates with SPEAKEASY by either directing passing data or by
creating SCA FSAVE files. Since both programs can read and write these files,
two way communication is possible. SPEAKEASY links can be easily done with the
B34SI/O command in the B34S display manager.
Links to SCA
The next file shows b34s calling sca, using the automatic ARIMA capability
in SCA, reloading the residuals and using the b34s matrix command to draw a high
resolution graph. This control file is available in the examples.mac file.
b34sexec options ginclude('gas.b34'); b34srun;
b34sexec options open('sca.dat') disp=unknown unit(28)$ b34srun$
b34sexec options open('sca.cmd') disp=unknown unit(29)$ b34srun$
b34sexec options clean(28)$ b34srun$
b34sexec options clean(29)$ b34srun$
b34sexec options dodos('erase c:\junk\scadata.fsv'); b34srun;
b34sexec pgmcall$ sca scafname=mydata$
pgmcards$
/$#==myrun
22
B34S / SAS Quick Start
--- these commands are required to load the b34s data.
--assign file 18. attrib access(read). external 'sca.dat'.
call procedure is mydata. file is 18.
----- User can place any sca commands after here. A number
--- of sample setups can be uncommented
--print age, ecg, chd, cat, wt
--crosstab cat, age.
--crosstab age, ecg, chd, cat. weight is wt.
--print gasin, gasout.
--acf gasin.
--regress variables are gasout gasin
--SCA Expert commands
--iarima gasout. hold residuals(res)
--estim utsmodel. method is exact.
--forecast utsmodel.
--VAR Identification
--ccm
gasin, gasout. maxlag is 12.
--stepar gasin, gasout. arfits are 1 to 6. @
--rccm are 1,2. output level(detailed).
--fsave series1. file is 'my.fsv'. dataset is test.
----iarima gasout.
estim utsmodel. method is exact. hold residuals(testres).
print testres.
fsave testres. file is 'scadata.fsv'. dataset is test.
stop.
return
/$#==
b34sreturn$
b34srun$
b34sexec options close(28)$ b34srun$
b34sexec options close(29)$ b34srun$
b34sexec options
dodos('scaw32 10000 /f:sca.cmd /p:myrun /o:sca.out')$ b34srun$
b34sexec options npageout
writeout('output from sca',' ',' ')
copyfout('sca.out')
dodos('erase sca.cmd','erase sca.out','erase sca.dat')
$
/$
/$ Data from SCA pulled back into MATRIX facility for further work
/$
b34sexec matrix;
call getsca('scadata.fsv', :member test);
call print(testres);
testres=goodrow(testres);
call graph(testres);
b34srun$
B34S links to LIMDEP, MATLAB, MINITAB, EXCEL etc will not be shown in this
document. Sample jobs are supplied in the examples.mac file.
Calling B34S under SAS
23
B34S / SAS Quick Start
The SAS system has extensive and very powerful data building capability.
While at one time there is a maximum of 98 b34s active variables, in SAS there
is effectively no limit to the number of variables that can be active at one
time. In b34s the DMF file can save up to 9999 series but not all can be loaded
at once. This suggests that it is desirable to be able to call b34s under SAS
for specialized calculations but use SAS for data building. The SAS macro
CB34SM.SAS was built to perform the link. The next job setup illustrates this
capability
* Simple job showing a branch from SAS to B34S ;
* One control file is built with data in the file;
%include 'c:\b34slm\cb34sm.sas';
data junk;
input x y;
cards;
11 22
33 44
55 66
99 77
77 88
;
proc means;
*
* Clean files **********************************
*
options noxwait;
run;
data _null_;
command ='erase myjob.b34';
call system(command);
*
* End of clean step ****************************
*
;
* Place B34S commands next after %readpgm ;
%readpgm
cards;
b34sexec list$ var x$
b34seend$
b34sexec regression$
model y = x$
b34seend$
b34sexec rr$ model y=x$ b34seend$
b34sexec describe$ b34seend$
b34sexec reg$ model y=x$ b34seend$
b34sexec options dispmoff$ b34srun$
;
run;
%cb34sm(data=junk, var=x y, u8='myjob.b34',
u3='myjob.b34',
options=dropmiss)
options noxwait;
run;
;
;
;
;
;
With this setup the user must run the file myjob.b34 which contains b34s control
commands and data. The next sample shows b34s running under SAS.
24
B34S / SAS Quick Start
* Simple job showing a branch from SAS to B34S;
* One control file is built with data in the file;
%include 'c:\b34slm\cb34sm.sas';
data junk;
input x y;
cards;
11 22
33 44
55 66
99 77
77 88
;
proc means;
*
* Clean files **********************************
*
options noxwait;
run;
data _null_;
command ='erase myjob.b34';
call system(command);
*
* End of clean step ****************************
*
;
* Place B34S commands next after %readpgm ;
%readpgm
cards;
b34sexec list$ var x$
b34seend$
b34sexec regression$
model y = x$
b34seend$
b34sexec rr$ model y=x$ b34seend$
b34sexec describe$ b34seend$
b34sexec reg$ model y=x$ b34seend$
b34sexec options dispmoff$ b34srun$
;
run;
%cb34sm(data=junk, var=x y, u8="myjob.b34",
u3="myjob.b34",
options=dropmiss)
options noxwait;
run;
*
;
* This step calls b34s and copies files
;
*
;
data _null_;
command ='c:\b34slm\b34sw.exe myjob.b34';
call system(command);
command ='copy b34s.log myjob.log';
call system(command);
command ='copy b34s.out myjob.out';
call system(command);
run;
endsas;
25
;
;
;
;
;
B34S / SAS Quick Start
Discussion of the commands in the job.
1. The below listed command loads the SAS macro cb34sm to process the
SAS/B34S link in the usual manner.
%include 'c:\b34slm\cb34sm.sas';
2. Before loading the b34s control files the next series of
commands erases any jobs of the same name
*
* Clean files **********************************
*
options noxwait;
run;
data _null_;
command ='erase myjob.b34';
call system(command);
*
* End of clean step ****************************
*
;
;
;
;
;
;
3. Next the user must place all B34S commands after the
SAS macro %readpgm. Note the last b34s command
b34sexec options dispmoff$ b34seend$
turns off the display
manager under windows 95 /NT
If this command is not used, B34S will process all commands
and return to the display manager.
*
* Place B34S commands next after %readpgm ;
%readpgm
cards;
b34sexec list$ var x$
b34seend$
b34sexec regression$
model y = x$
b34seend$
b34sexec rr$ model y=x$ b34seend$
b34sexec describe$ b34seend$
b34sexec reg$ model y=x$ b34seend$
b34sexec options dispmoff$ b34srun$
;
run;
%cb34sm(data=junk, var=x y, u8='myjob.b34',
u3='myjob.b34',
options=nohead)
options noxwait;
run;
;
4. Steps 1-3 have made the b34s command file myjob.b34
If the user wants to execute b34s under SAS, add the following
commands to the job.
26
B34S / SAS Quick Start
*
* This step calls b34s and copies files
*
data _null_;
command ='c:\b34slm\b34sw.exe myjob.b34';
call system(command);
command ='copy b34s.log myjob.log';
call system(command);
command ='copy b34s.out myjob.out';
call system(command);
run;
endsas;
;
;
;
The next example places b34s commands in one file and data in another. It should
be used for large datasets since in this case it is not desirable to have the
data in the command file. The control file is myjob.b34
Discussion.
* Simple job showing a branch from SAS to B34S ;
* One control file is built with data in the file;
* Data and B34S control statements are in 1 file;
* The job TSASB342.SAS shows same job with data in
%include 'c:\b34slm\cb34sm.sas';
data junk;
input x y;
cards;
11 22
33 44
55 66
99 77
77 88
;
proc means;
*
* Clean files **********************************
*
options noxwait;
run;
data _null_;
command ='erase myjob.b34';
call system(command);
command ='erase mydata';
call system(command);
*
* End of clean step ****************************
*
;
* Place B34S commands next after %readpgm ;
%readpgm
cards;
b34sexec list$ var x$
b34seend$
b34sexec regression$
model y = x$
b34seend$
27
different file;
;
;
;
;
;
B34S / SAS Quick Start
b34sexec rr$ model y=x$ b34seend$
b34sexec describe$ b34seend$
b34sexec reg$ model y=x$ b34seend$
b34sexec options dispmoff$ b34srun$
;
run;
%cb34sm(data=junk, var=x y, u8='mydata',
u3='myjob.b34',
options=nohead)
options noxwait;
run;
*
;
* This step calls b34s and copies files
;
*
;
data _null_;
command ='c:\b34slm\b34sw.exe myjob.b34';
call system(command);
command ='copy b34s.log myjob.log';
call system(command);
command ='copy b34s.out myjob.out';
call system(command);
run;
endsas;
The only difference between this job and the example above is that
the lines
command ='erase mydata';
call system(command);
and
%cb34sm(data=junk, var=x y, u8='mydata',
u3='myjob.b34',
have been changed.
The line 'erase mydata' is needed to prevent the new data from being
appended to the old data.
The lines
%cb34sm(data=junk, var=x y, u8='mydata',
u3='myjob.b34',
place the data in mydata and tell b34s to read from mydata.
Be sure and use ' not ".
It is possible to have multiple b34s datasets built in SAS. The next setup uses
the control file ft03f001.dat which is the default. This job shows the minimum
needed to run the program.
*
*
*
*
Shows SAS calling B34S where two steps are passed;
The job TSASB34S.SAS shows a simple job;
The job TSASB341.SAS shows two calls to cb34sm ;
The job TSASB342.SAS shows BY variable processing;
28
B34S / SAS Quick Start
* The job TSASB343.SAS shows data and control cards in 1 file;
*
;
* Clean files **********************************
;
*
;
options noxwait;
run;
data _null_;
command ='erase ft03f001.dat';
call system(command);
command ='erase ft08f001';
call system(command);
*
;
* End of clean step ****************************
;
*
;
%include 'c:\b34slm\cb34sm.sas';
data junk;
input x y;
cards;
11 22
33 44
55 66
99 77
77 88
;
proc means;
* Place B34S commands next after %readpgm ;
%readpgm
cards;
b34sexec list$ var x$
b34seend$
b34sexec regression$
model y = x$
b34seend$
b34sexec rr$ model y=x$ b34seend$
;
run;
%cb34sm(data=junk, var=x y, options=nohead)
* pass # 2
..... data is built;
data new; set junk;
xx=x*x;
yy=y**3;
proc means;
%readpgm
cards;
b34sexec list$
b34seend$
b34sexec regression$
model y = x xx yy$
b34seend$
b34sexec rr$ model y=x xx yy$ b34seend$
;
%cb34sm(data=new, var=x y xx yy, options=nohead)
run;
Warning.
The data cleaning step is needed!!!!!
29
B34S / SAS Quick Start
The next job shows both data and commands in one file. The default name of
ft03f001 is used.
* Simple job showing a branch from SAS to B34S ;
*
;
* Clean files **********************************
;
*
;
options noxwait;
run;
data _null_;
command ='erase ft03f001.*';
call system(command);
*
;
* End of clean step ****************************
;
*
;
%include 'c:\sasb34s\cb34sm.sas';
* Place B34S commands next after %readpgm ;
data junk;
input x y;
cards;
11 22
33 44
55 66
99 77
77 88
;
proc means;
* Place B34S commands next after %readpgm ;
%readpgm
cards;
b34sexec list$ var x$
b34seend$
b34sexec regression$
model y = x$
b34seend$
b34sexec rr$ model y=x$ b34seend$
;
run;
%cb34sm(data=junk, u8='ft03f001', u3='ft03f001', var=x y,
options=nohead)
In the next sample job BY variable processing is done using two files. This job
illustrates the power of the SAS system.
* Shows calling B34S under SAS when BY variable processing is used;
* This job uses two files;
*
;
* Clean files **********************************
;
*
;
options noxwait;
run;
data _null_;
command ='erase ft03f001.dat';
call system(command);
30
B34S / SAS Quick Start
command ='erase ft08f001';
call system(command);
*
;
* End of clean step ****************************
;
*
;
%include 'c:\b34slm\cb34sm.sas';
data junk;
input x y;
cards;
1 7
2 5
2 4
1 6
1 3
2 6
3 6
3 7
3 4
1 8
2 4
;
proc means;
* Place B34S commands next after %readpgm ;
%readpgm
cards;
b34sexec list$
b34seend$
;
run;
%cb34sm(data=junk, var=x y, options=nohead, by=x)
The above examples show how the power of the SAS system can be used to
build data which in turn is passed to B34S for processing. The above jobs
provide templates that can be modified and used in actual applications. Since
B34S can call LIMDEP and RATS, it is possible to make a three-way program branch
to these other systems.
B34S Calling SAS
The next sample job shows B34S loading the gas data and calling SAS. SAS
output is copied back into the b34s output file.
b34sexec options include('c:\b34slm\gas.b34')$ b34srun$
/$ Loads B34S data in sas command file TESTSAS.SAS
/$ User can optionally add SAS commands after PGMCARDS$
/$ Under Windows 95 / nt need to place a pause after SAS command
/$ This allows SAS to finish before b34s starts to look for the
/$ files
/$
B34SEXEC OPTIONS OPEN('TESTSAS.SAS') UNIT(29) DISP=UNKNOWN$ B34SRUN$
B34SEXEC OPTIONS CLEAN(29) $ B34SEEND$
B34SEXEC PGMCALL IDATA=29 ICNTRL=29$
SAS
$
PGMCARDS$
proc means; run;
proc reg;
31
B34S / SAS Quick Start
model gasout = gasin;
run;
proc autoreg;
model gasout=gasin / method=ml nlag=3;
run;
B34SRETURN$
B34SRUN $
B34SEXEC OPTIONS CLOSE(29)$ B34SRUN$
B34SEXEC OPTIONS SYSTEM('SAS TESTSAS'
'pause
')$ B34SRUN$
B34SEXEC OPTIONS NPAGEOUT NOHEADER
WRITEOUT('
','Output from SAS',' ',' ')
WRITELOG('
','Output from SAS',' ',' ')
COPYFOUT('TESTSAS.LST')
COPYFLOG('TESTSAS.LOG')
SYSTEM('ERASE TESTSAS.SAS','ERASE TESTSAS.LST',
'ERASE TESTSAS.LOG')
$
B34SRUN$
B34SEXEC OPTIONS HEADER$ B34SRUN$
Summary
The B34S is a full-featured econometric system that works well with other
software systems such as SAS, MATLAB, RATS, SCA, SPEAKEASY and LIMDEP. B34S has
a number of unique features which make it a powerful complementary program that
can be used with these other systems. The B34S control language is powerful and
flexible and shares many of the design features of SAS.
32