Previous Page | Next Page

Functions and CALL Routines

FSEP Function

Sets the token delimiters for the FGET function.
Category: External Files

See Also


FSEP(file-id,characters<,'x' |'X'>)



is a numeric variable that specifies the identifier that was assigned when the file was opened, generally by the FOPEN function.


is a character constant, variable, or expression that specifies one or more delimiters that separate items in the File Data Buffer (FDB). Each character listed is a delimiter. That is, if character is #@, either # or @ can separate items. Multiple consecutive delimiters, such as @#@, are treated as a single delimiter.

Default: blank
'x' | 'X'

specifies that the character delimiter is a hexadecimal value.

Restriction: 'x' and 'X' are the only valid values for this argument. All other values will cause an error to occur.
Restriction: If you pass 'x' or 'X' as the third argument, a valid hexadecimal string must be passed as the second argument, character. Otherwise, the function will fail. A valid hexadecimal string is an even number of 0-9 and A-F characters.
Tip: If you use a macro statement, then quotation marks enclosing x or X are not required.


FSEP returns 0 if the operation was successful, [ne]0 if it was not successful.


An external file has data in this form:

John J. Doe,Male,25,Weight Lifter
Pat O'Neal,Female,22,Gymnast

Note that each field is separated by a comma.

This example reads the file that is identified by the fileref MYFILE, using the comma as a separator, and writes the values for NAME, GENDER, AGE, and WORK to the SAS log. Note that in a macro statement you do not enclose character strings in quotation marks, but a literal comma in a function argument must be enclosed in a macro quoting function such as %STR.

%let fid=%sysfunc(fopen(myfile));
%let rc=%sysfunc(fsep(&fid,%str(,)));
%do %while(%sysfunc(fread(&fid)) = 0);
   %let rc=%sysfunc(fget(&fid,name));
   %let rc=%sysfunc(fget(&fid,gender));
   %let rc=%sysfunc(fget(&fid,age));
   %let rc=%sysfunc(fget(&fid,work));
   %put name=%bquote(&name) gender=&gender 
      age=&age work=&work;
%let rc=%sysfunc(fclose(&fid));

See Also


FCLOSE Function

FGET Function

FOPEN Function

FREAD Function

MOPEN Function

Previous Page | Next Page | Top of Page