Chapter Contents

Previous

Next
NEWVAR

NEWVAR



Adds a column to a new SAS table

Category: SAS Table


Syntax
Details
Example
See Also

Syntax

sysrc=NEWVAR(table-id,col-name,type<,length<,label
<,format<,informat>>>>);

sysrc
contains the return code for the operation:
0 successful
[ne]0 not successful

Type: Numeric

table-id
is the identifier that was assigned when the table was opened. If table-id is invalid, the program halts. The SAS table must be opened with an open mode of NEW.

Type: Numeric

col-name
is the name to assign to the new column. The name must be a valid SAS name.

Type: Character

type
specifies the data type of the new column:
'C' character
'N' numeric

Type: Character

length
is the length of the new column. For a character column, this value can be between 1 and 32,767. For a numeric column, it can be between 3 and 8. On some systems, the minimum length can be 2.

Type: Numeric

label
is the label for the new column. This is a character string from 1 to 40 characters. If the label contains single quotes, use two single quotes for each of these internal single quotes, or surround the label with double quotes. Each set of two single quotes counts as one character.

Type: Character

format
is the format for the new column. This must be a valid SAS format name. Formats can be either defined by the user or supplied by SAS software. If not specified, SAS assigns a default format. If type is C, then a character format should be specified. Otherwise, a numeric format should be specified.

Type: Character

informat
is the informat for the new column. This must be a valid SAS informat name. Informats can be either defined by the user or supplied by SAS software. If not specified, SAS assigns a default informat. If type is C, then a character informat should be specified. Otherwise, a numeric informat should be specified.

Type: Character


Details

CAUTION:
The table must be opened in NEW mode, or SCL halts the program. Opening an existing SAS table in NEW mode creates a new table that overwrites the old table. When the table is closed after using NEWVAR, the SAS table is created with zero rows. If the column name matches a column name that was defined for the table by a previous NEWVAR function, the new definition overrides the previous definition.  [cautionend]


Example

Open a new SAS table, MYDATA, in NEW mode, and then add the column AGE, which is numeric, and NAME, which is character. AGE has a length of 8, and NAME has a length of 20. The label of NAME is set to Last Name.

dsid=open('mydata','n');
rc=newvar(dsid,'num','n',8);
rc=newvar(dsid,'char','c',20,'Last Name');
rc=close(dsid);

See Also

OPEN


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.