我使用
连接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”以防万一这是问题的一部分。抱歉无法发布日志。你能帮忙吗?
答案 0 :(得分:0)
如果您想转换为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;