SAS 更改日期格式 [英] SAS change date format

查看:20
本文介绍了SAS 更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义一个采用以下格式的日期格式:12JAN2010

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 语句应该是

So the correct set statement would be

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_diagnosticdate_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆