在 SAS 数据步骤 monyy5 中将日期转换为字符串.到 yymmn6 [英] Convert Date to String in SAS data step monyy5. to yymmn6

查看:9
本文介绍了在 SAS 数据步骤 monyy5 中将日期转换为字符串.到 yymmn6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SAS EG 中,在数据步骤中,我尝试将日期转换为以下格式的字符串:

In SAS EG, in a data step, I am trying to convert from a date to a string in the following formats:

JUN18'201806'

我可以使用如下数据步骤转换相反的方向:

I am able to convert the opposite direction using a data step as follows:

data date;
length b $6;
b='201806';
new_b=input(b, yymmn6.);
format new_b monyy5.;

结果是 new_b = JUN18.我尝试了相反的方向,但有些东西刚刚关闭,我无法弄清楚我错过了什么.有谁知道如何转换这些数据类型?

The result is that new_b = JUN18. I have tried the opposite direction and something is just off and I can't figure out what I am missing. Does anyone know how to convert these data types?

谢谢.

推荐答案

使用 PUTPUTN 函数将 SAS 日期值转换为包含日期表示的字符串.

Use the PUT or PUTN function to convert a SAS date value to a string containing a date representation.

data _null_;

  mydate = '18JUN2018'D;  
  * variable is numeric and contains a SAS date value;

  format mydate monyy.; 
  * variable given a format that is used when value is output (PROC rendered or PUT);

  put mydate=;  
  * the LOG will show JUN18, mydate is still a numeric holding a SAS date value;

  mydate_str = put (mydate, yymmN.);  
  * put returns the formatted value using yymmN representation of the data value;
  * yymmN format is different than monyy format associated with the variable,
  * and thus this is the 'conversion';

  put mydate_str=; 
  * the LOG will show 201806, mydate_str is a $6 variable and can not be used in date value computations;

run;

VVALUE 函数可用于使用其当前格式属性获取变量的格式化值(字符串中的数据值表示).

The VVALUE function can be used to obtain the formatted value (the data value representation in a character string) of a variable using its current format attribute.

  length my_date_formatted_str $10;
  mydate_formatted_str = vvalue(mydate);
  put mydate_formatted_str=;

这篇关于在 SAS 数据步骤 monyy5 中将日期转换为字符串.到 yymmn6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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