SAS使用SQLDF转换为R转换
感谢您使用SQLDF将以下SAS代码转换为R的某人。我正在努力更改数据类型并在一个步骤中应用子字符串功能。
同样,在第二步中,我不确定如何在另一个可以在稍后阶段使用的新字段中保存字段值。
proc sql;
create table noodle as
select MATRL_NBR,
put(PLANT, z4.) as PLANT_NBR,
PLANT_DESC,
MFG_DT,
input(substr(FISC_PD, 5, 4), best32.) as FISC_YR,
input(substr(FISC_PD, 1, 3), best32.) as FISC_PD,
input(substr(FISC_WK, 1, 3), best32.) as FISC_WK,
PLANNED_ZNL,
ACTUAL_ZNL,
CRIT_SKU,
IP_BRAND,
IP_BU,
CATG,
MATRL_TYPE
from comb
;
quit;
proc sql noprint;
select max(FISC_YR), max(FISC_WK)
into :CURRENT_FISC_YR, :CURRENT_FISC_WK
from noodle;
quit;
Appreciate if someone of you help me to convert below SAS code to R using SQLDF. I'm struggling to change the data type and apply sub string function in one single step.
Also In second step I'm not certain how to save the value of field in another new field which can be used in later stage.
proc sql;
create table noodle as
select MATRL_NBR,
put(PLANT, z4.) as PLANT_NBR,
PLANT_DESC,
MFG_DT,
input(substr(FISC_PD, 5, 4), best32.) as FISC_YR,
input(substr(FISC_PD, 1, 3), best32.) as FISC_PD,
input(substr(FISC_WK, 1, 3), best32.) as FISC_WK,
PLANNED_ZNL,
ACTUAL_ZNL,
CRIT_SKU,
IP_BRAND,
IP_BU,
CATG,
MATRL_TYPE
from comb
;
quit;
proc sql noprint;
select max(FISC_YR), max(FISC_WK)
into :CURRENT_FISC_YR, :CURRENT_FISC_WK
from noodle;
quit;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为以下将实现您想要的东西:
您可能需要将
用作double
或作为float
而不是作为
cast()功能取决于您需要的数字数据类型,fisc_yr,fisc_pd和fisc_wk。中的
作为intI think the following will achieve what you want:
You might want to use
as double
oras float
instead ofas int
in thecast()
functions depending on the numeric data type you require for FISC_YR, FISC_PD and FISC_WK.