1

目前我有一个程序在 SAS 中处理原始数据,运行如下查询:

/*this code joins the details onto the spine, selecting the details 
 that have the lowest value2 that is greater than value, or if there are none
 of those, then the highest value2*/
/*our raw data*/
data spine; 
    input id value; 
    datalines;
    1 5
    2 10
    3 6
;
run;

data details;
    input id value2 detail $; 
    datalines;
    1 6 foo
    1 8 bar
    1 4 foobar
    2 8 foofoo
    2 4 barbar
    3 6 barfoo
    3 2 foobarfoo
;
run;

/*cartesian join details onto spine, split into highs and lows*/    
proc sort data = spine;
by id; 
run; 

proc sort data= details;
    by id; 
run;

data lows highs;
    join spine details;
    by id;
    if value2 ge value then output highs;
    else output lows;
run;

/*grab just the first/last of each set*/
proc sort data =lows;
by id value2;
run;

proc sort data = highs;
by id value2; 
run;

data lows_lasts;
    set lows;
    by id;
    if last.id;
run;

data highs_firsts;
    set highs;
    by id;
    if first.id;
run;

/*join the high value where you can*/
data join_highs;
    merge spine(in = a)
    highs_firsts ;
    by id;
    if a;
run;

/*split into missing and not missng*/
data not_missing still_missing;
    set join_highs;
    if missing(value2) then output still_missing;
    else output not_missing; 
run;

/*if it doesn't already have a detail, then attach a low*/
data join_lows;
    merge still_missing(in = a)
    lows_lasts ;
    by id; 
    if a;
run;

/*append the record that had a high joined, and the record that had a low joined, together*/ 
data results;
    set not_missing join_lows;
run; 

你得到图片。有很多这样的数据处理报表,每周都会在新记录上运行。

还进行数据转换(例如清理/解析地址)。

现在 - 这种处理可以使用 SQL 来完成。

问题是——这是否适合使用关系数据库?还是应该仅将数据库用于数据存储和检索?

考虑到我们正在讨论具有多达 1000 万行的表。

4

2 回答 2

1

SAS专为您提到的操作而设计!您绝对可以在 RDBMS 中完成大部分这些处理,但与 SAS 功能相比,典型 RDBMS 的分析能力有限。SAS 中也有一些优雅的结构,例如 SAS First 和 Last 处理的 SQL 替代方案更加麻烦。代码可以每周轻松地组织和安排为流。

主要问题是,您为什么要使用 RDBMS,您将从它的哪些优势中受益?我想到了两个潜在的优势:

  • 多用户使用:RDBMS 的内置锁定和事务管理允许多个数据库用户同时访问数据库。我认为您的情况并非如此。
  • 记录负载:在数十亿条记录的情况下,SAS 数据集的大小可能会变得难以处理,即使打开了 COMPRESS 选项(速度也可能是一个问题)。在这种情况下,最好将数据存储在 RDBMS 中并通过 SAS/Access 接口访问它。我认为您的情况也不是这种情况。

如果您使用 SAS 解决方案中的 RDBMS,请注意您可能必须重写代码的某些部分,因为如果您使用 libname 方法运行某些 SAS 函数,它们将无法与 RDBMS-s 一起使用。使用 FedSQL(SAS 9.4 中引入的 ANSI SQL:1999 核心标准的 SAS 实现)正在解决这个问题。

另请注意,在某些特殊情况下,使用 SAS 与使用 RDBMS可能会得到不同的结果。

于 2013-11-01T20:48:03.103 回答
0

正如您所指出的,这种类型的处理可以在 RDBMS 中完成,但不仅仅是任何 RDBMS。您将需要一个符合最新 ANSI SQL 标准或至少支持WINDOW具有功能的PARTITION功能的 RDMBS。例如:PostgreSQL、Teradata、SQL Server 2012 等... 注意:MySQL 不支持WINDOW函数,因此缺失。

于 2013-11-01T06:51:22.800 回答