SAS更改日期格式 [英] SAS change date format
问题描述
我想定义一个采用以下格式的日期格式:2010年1月12日
I want to define a date format that takes the following format : 12JAN2010
我尝试使用此代码:
/* partie B question 2*/
data projet.Ophtalmo_new;
set projet.Ophtalmo_new (RENAME=(date_diagnostic=date_dia)) (RENAME=
(date_examen=date_exa));
date_diagnostic = input (date_dia, DDMMYY10.);
date_examen = input (date_exa, DDMMYY10.);
format date_diagnostic date_examen date9.;
run;
但是它向我发送了以下语法错误:
But it sends me the following syntax error :
ERROR 22-322: Syntax error, expecting one of the following: un nom, une chaîne
entre guillemets, ;,
CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT,
_DATA_, _LAST_, _NULL_.
我仍然是sas的初学者,我无法设法使其正常工作,希望您能有所帮助,谢谢.
I'm still a sas beginner and i can't manage to get it to work properly, hope you can help, thanks.
推荐答案
数据集选项的语法是单个括号表达式. rename
选项适合:
The syntax for data set options is a single parenthetical expression. The rename
option fits within:
data-set-name ( ... options ... rename=(...) );
RENAME
选项的语法如下:
rename=(old-name-1=new-name-1 old-name-2=new-name-2 ...)
所以正确的set
语句应该是
set projet.Ophtalmo_new (RENAME=(date_diagnostic=date_dia date_examen=date_exa));
因为您声明自己是初学者,所以我添加了此部分.
Because you state your are a beginner I added this section.
您显示的代码指示最初名为date_diagnostic
和date_examen
的变量的输入.如果这些变量确实是要启动的字符变量,则必须输入以将字符转换为SAS日期(这只是具有特殊含义的数字).但是,如果变量已经是SAS日期,且格式与您想要的格式不同,则只需更新变量的格式(或使用FORMAT语句更改在PROC步骤中使用的格式)>
The code you show indicates input of the variables originally named date_diagnostic
and date_examen
. If these variables are indeed character variables to start, then the input is necessary to convert from character to a SAS date (which is simply a number with special meaning). If, however, the variables were already a SAS date with a format different than the one you want, you only need to update the format of the variables (or use a FORMAT statement to change the format to use during a PROC step)
data have;
x = '01-jan-2017'd;
format x ddmmyy10.;
run;
* demonstrate that the permanent format of x is ddmmyy10.;
data _null_;
put x=;
run;
* demonstrate temporary formatting of variable during step;
data _null_;
set have;
format x date9.; * modify the format temporarily during execution of data _null_;
put x=;
run;
* permanently change format of variable;
* only the dataset metadata (or header data) changes, the entire data set is NOT rewritten;
proc datasets nolist lib=work;
modify have;
format x date9.;
run;
* demonstrate that the permanent format of x has changed to date9.;
data _null_;
set have;
put x=;
run;
这篇关于SAS更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!