Chapter Contents |
Previous |
Next |
SAS Component Language: Reference |
Before a program can manipulate the data, it must read the data from the table. After column values are changed, the program can update the values of columns in the table. In addition to updating existing column values, programs also can add new rows or delete obsolete rows.
After a SAS table is open, you can access any column value for any row in the SAS table. The first step in accessing the data involves reading (or copying) a row from the SAS table to the TDV--for example, by using the FETCH function. By default, the FETCH function starts with the first row in the SAS table and reads the next row from the SAS table each time it executes.
Linking SAS Table Columns And SCL Variables |
If columns of a SAS table and SCL variables have the same names and types, then you can use the SET routine to link all of them automatically with a single program statement. The SET routine is typically invoked immediately following the OPEN function.
Note: If you use the SET routine and then also use the
PUTVARC or PUTVARN routine for an SCL variable that has a matching SAS table
column, the SET routine overrides the PUTVARC or PUTVARN routine. Doing this
is inefficient because duplicate actions are performed.
When the SCL variables do not have the same names or types as SAS table columns, you must use a GETVARC or GETVARN statement (for character and numeric values, respectively) for each unmatched column to link them from the TDV to the SDV. Once the columns have been manipulated, use an individual PUTVARC or PUTVARN routine to link each one from the SDV back to the TDV.
Note: The GETVARC and GETVARN functions establish
only a temporary link between a SAS table column and an SCL variable. When
the statement executes, the columns are linked. After the statement executes,
the link is terminated. Therefore, you must use the GETVARC or GETVARN function
one time for each SAS table column that you want to link. This is different
from the SET routine, which establishes a permanent link between any matching
SAS table and SCL variables until the open SAS table is closed.
Determining a Column's Position in a SAS Table |
INIT: control enter; houses=open('sasuser.houses','u'); if (houses=0) then _msg_=sysmsg(); else do; vtype=varnum(houses,'style'); vsize=varnum(houses,'sqfeet'); vbedrms=varnum(houses,'bedrooms'); vbathrms=varnum(houses,'baths'); vaddress=varnum(houses,'street'); vcost=varnum(houses,'price'); link getvalue; end; return; MAIN: ...more SCL statements... return; TERM: if (houses>0) then rc=close(houses); return; GETVALUE: rc=fetch(houses); type=getvarc(houses,vtype); size=getvarn(houses,vsize); bedrms=getvarn(houses,vbedrms); bathrms=getvarn(houses,vbathrms); address=getvarc(houses,vaddress); cost=getvarn(houses,vcost); return;
Using Table-Lookup Techniques |
To validate a field value, you can use the LOCATEC, LOCATEN, or WHERE function to search a secondary SAS table for a specific character or numeric value that has been entered by a user. For example, you might want to make sure that users enter names that exist in another SAS table. You also can use these techniques to display text from a secondary SAS table, based on values that users enter in the fields. For example, when a user enters a valid name in the Employee Name field, you can look up the associated sales region and sales to date in the secondary SAS table and then display this information in the window.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.