【问题标题】:Convert YYYYMMDD date format and Calculate Industry average by date转换 YYYYMMDD 日期格式并按日期计算行业平均值
【发布时间】:2017-10-13 19:42:01
【问题描述】:

我使用连接

proc sql; 
connect to odbc as odbc("......"); 
create table work.market as select distinct * from connection to odbc( 
select distinct C.Product#, A.county, B.DT, profit2, Rev2)

From Mtable.duv A, Ttable.duv B, otable C
Where B.Product# = C.Product#
and   B.Product# = A.Product#

and   B.Dt = C.Dt
and   B.dt between A.dt_start and dt_end
and   B.dt between 20140331 and 20170630
);
disconnect from odbc;
quit;

data work.smallmarket;
set work.market;
where country=Nigeria;
NetMargin=profit2/Rev2;
keep Product# NetMargin DT;
run;

1) 如果 DT 是我的日期,如何将日期格式从 YYYYMMDD 更改为 SAS 日期格式,例如 01Jan1960?当我运行上述内容时,我得到了我的数据,但日期显示为 20170630 例如。如何按日期列转换以显示 30Jun2017 格式。我发布了我是如何获得我的初始数据集“work.market”的,以防万一这是问题的一部分。抱歉不能发日志。你能帮忙吗?

【问题讨论】:

  • 请包含该代码中的日志,它看起来根本不正确。您显示的代码也与您的问题无关。您能否发布与您的问题相关的尝试以及您的数据是什么样的?
  • 第一个问题很好,我认为你有它的方式。第二个你需要单独询问,正如 Reeza 所说,你需要展示你的尝试。

标签: sql sas


【解决方案1】:

如果您想转换为 SAS 日期格式,您有两个地方可以做到这一点。

首先,您可以在create table 语句中进行;那是 SAS 语句,而不是 SQL Server/任何语句。

proc sql; 
connect to odbc as odbc("......"); 
create table work.market as select Product#, county, dt format=date9.,profit2, rev2
  from connection to odbc( 
select distinct Product#, county, DT, profit2, Rev2);

您可以做到的第二个地方是在下面的数据步骤中。

data work.smallmarket;
set work.market;
where country=Nigeria;
format dt date9.;
NetMargin=profit2/Rev2;
keep Product# NetMargin DT;
run;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 2018-10-27
    • 2014-06-04
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多