楼主: 8xiicecream
6178 7

sas 日期 取上个月值 [推广有奖]

  • 0关注
  • 0粉丝

小学生

64%

还不是VIP/贵宾

-

威望
0
论坛币
7 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
55 点
帖子
8
精华
0
在线时间
2 小时
注册时间
2010-2-25
最后登录
2010-6-15

楼主
8xiicecream 发表于 2010-4-1 17:11:54 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
大家好,我是sas新手,请教一个菜鸟问题,
我想知道上个月的年月信息,如何做到?

假设今天是2010-04-02,我想得到2010 和03两个信息
如果今天是2010-01-05, 我想得到2009 和12 这两个信息

请问怎么做最简单?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:大家好 最简单 怎么做 SAS

回帖推荐

soporaeternus 发表于3楼  查看完整内容

intnx函数...

本帖被以下文库推荐

沙发
醉_清风 发表于 2010-4-1 17:17:39
data _null_;
    call symput('mth',put(intnx('month',today(),-1,'end'),yymmn6.));
run;
%put &mth;
如果一定要取年月,可用year和month函数
从来不需要想起 永远也不会忘记

藤椅
soporaeternus 发表于 2010-4-1 17:22:04
  1. data d;
  2.         input date:yymmdd10.;
  3.         yyyy=put(year(intnx("MONTH",date,-1,"END")),$4.);
  4.         mm=put(month(intnx("MONTH",date,-1,"END")),z2.);
  5.         format date yymmdd10.;
  6.         datalines;
  7.         2010-04-02
  8.         2010-01-05
  9.         ;
  10. run;
复制代码
intnx函数...
已有 2 人评分经验 论坛币 热心指数 收起 理由
bakoll + 3 + 3 精彩帖子
crackman + 60 + 100 + 1 精彩帖子

总评分: 经验 + 63  论坛币 + 103  热心指数 + 1   查看全部评分

Let them be hard, but never unjust

板凳
醉_清风 发表于 2010-4-1 17:24:20
凡是涉及到时间计算的 intnx还真是好用
从来不需要想起 永远也不会忘记

报纸
8xiicecream 发表于 2010-4-1 17:31:10
4# 醉_清风

地板
8xiicecream 发表于 2010-4-1 17:37:52
谢谢大家,我的真实需求是取当前时间的上个月的信息,
假设是 1st of Apr 那我要的值是 Mar 2010
月的显示要英文的

如果正好是跨年,假设是2010 01 月运行的,那我需要的是 Dec 2009

7
8xiicecream 发表于 2010-4-1 19:18:48
got it now. thanks much every one :)

          call symput('rmth',substr(put(intnx('month',today(),-1,'end'),MONYY7.),1,3));
          call symput('ryth',substr(put(intnx('month',today(),-1,'end'),MONYY7.),4,4));

8
bobguy 发表于 2010-4-3 22:40:14
醉_清风 发表于 2010-4-1 17:17
data _null_;
    call symput('mth',put(intnx('month',today(),-1,'end'),yymmn6.));
run;
%put &mth;
如果一定要取年月,可用year和month函数
醉_清风,

The symput is replaced by symputx that takes care of type conversion + trailing space elimination.

Another useful function dealing with date is "intck".



49   data _null_;
50       call symputx('mth',month(intnx('month',today(),-1,'end')));
51   run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


52   %put >>>&mth<<<;
>>>3<<<

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-22 07:30