开发者

What's the easiest way to use SQLite with SAS?

I want to investigate how to access SQLite DB from SAS. What's the easiest way of doing this? Is there a SAS 开发者_如何学编程product that we can license to do that? I don't want to use ODBC drivers as that seems to have been written a long time ago and is not officially part of SQLite.


SAS supports reading data from pipes (in a unix environment). Essentially, you can set up a filename statement to execute an sqlite command in the host environment, then process the command output as if reading it from a text file.

SAS Support page: http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/viewer.htm#pipe.htm

Example:

*----------------------------------------------
* (1) Write a command in place of the file path
*     --> important: the 'pipe' option makes this work
*----------------------------------------------;

filename QUERY pipe 'sqlite3 database_file "select * from table_name"';



*----------------------------------------------
* (2) Use a datastep to read the output from sqlite
*----------------------------------------------;

options linesize=max; *to prevent truncation of results;

data table_name;

   infile QUERY delimiter='|' missover dsd lrecl=32767;

   length 
      numeric_id 8
      numeric_field 8
      character_field_1 $40
      character_field_2 $20
      wide_character_field $500
   ;

   input
      numeric_id 
      numeric_field $
      character_field_1 $
      character_field_2 $
      wide_character_field $
   ;

run;



*----------------------------------------------
* (3) View the results, process data etc.
*----------------------------------------------;

proc contents;
proc means;
proc print;
run;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜