全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学
4191 8
2006-11-25
<P>在网上比较容易找到一个破解了时间限制的<FONT face="Times New Roman">SAS8</FONT>版本,但是这版本用不了<FONT face="Times New Roman">EM</FONT>而且<FONT face="Times New Roman">today</FONT>函数的值也是不正确的。但是平常我们是需要用到时间值的,我写了个程序来弥补这个不足,用<FONT face="Times New Roman">sas</FONT>自身的功能来实现<FONT face="Times New Roman">today</FONT>函数的功能:</P>
<P><FONT face="Times New Roman"><o:p></o:p></FONT></P>
<P>用法:</P>
<P><FONT face="Times New Roman">1</FONT>在程序的开始加入以下代码:</P>
<P><FONT face="Times New Roman">  %include “path”;</FONT></P>
<P><FONT face="Times New Roman">path </FONT>是你存放程序的物理绝对路径。如果你放在<FONT face="Times New Roman">d:\ </FONT>则<FONT face="Times New Roman">path</FONT>就是<FONT face="Times New Roman">d:\todayV1.sas</FONT>了。</P>
<P>注意:这个程序会清除以前的<FONT face="Times New Roman">output</FONT>的,所以最好是先运行了程序再运行其他程序。</P>
<P><FONT face="Times New Roman">2</FONT>就是在开<FONT face="Times New Roman">SAS</FONT>的时候运行,把这个程序放到<FONT face="Times New Roman">SAS</FONT>的自动批处理文件中,这样就不会有清除有用<FONT face="Times New Roman">output</FONT>的危险了。</P>
<P><FONT face="Times New Roman"><o:p></o:p></FONT></P>
<P>这个程序会产生<FONT face="Times New Roman">3</FONT>个<FONT face="Times New Roman">macro</FONT>变量<FONT face="Times New Roman">,</FONT>如下表:</P>
<P>               name     : value                                <o:p></o:p></P>
<P align=left>            &amp;today_date : 25Nov2006                          <o:p></o:p></P>
<P align=left>              &amp;today      : "25Nov2006"d                      <o:p></o:p></P>
<P align=left>              &amp;date       : 20061125                           <o:p></o:p></P>
<P>举例说明使用方法:</P>
<P><FONT face="Times New Roman">1.  </FONT>生成按日子排列的<FONT face="Times New Roman">dataset</FONT>;</P>
<P><FONT face="Times New Roman">data xx_&amp;date;</FONT></P>
<P><FONT face="Times New Roman">dataset</FONT>的名字就是按<FONT face="Times New Roman">xx_20061125</FONT>的方式排列了。</P>
<P><FONT face="Times New Roman">2</FONT>.生成连续<FONT face="Times New Roman">N</FONT>个月的最后一天的日子;代码如下:</P>
<P align=left><B>%macro</B> month(N);<o:p></o:p></P>
<P align=left>data _null_;<o:p></o:p></P>
<P align=left>%do i = <B>0</B> %to %eval(&amp;n.);<o:p></o:p></P>
<P align=left>call symput ("month&amp;i.",put(intnx("month",&amp;today.,-&amp;i,"end"),yymmddn8.));<o:p></o:p></P>
<P align=left>%end; <o:p></o:p></P>
<P align=left>run;<o:p></o:p></P>
<P align=left><B>%mend</B>;<o:p></o:p></P>
<P align=left><o:p></o:p></P>
<P>%<B><I>month</I></B>(<B>2</B>);</P>
<P>
74184.rar
大小:(920 Bytes)

 马上下载

本附件包括:

  • todayV1.sas

<br></P>
<P>程序版权没有,翻版不究。</P>
<P>不过,希望大家能保留我在程序中的版权信息。谢谢</P>

[此贴子已经被作者于2006-11-27 17:27:43编辑过]

二维码

扫码加我 拉你入群

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

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

全部回复
2006-11-25 20:45:00
<P>/*********************************************************************/<BR>/**    Sakunamary Xiao <a href="mailto:Copyright@2006" target="_blank" >Copyright@2006</A> All reserved             **/<BR>/**    this SAS program is create by Sakunamary Xiao           **/<BR>/**    user can copy ,use and deliver this program             **/<BR>/**    freely . Please keep the message when the               **/<BR>/**    program is delivered.                                   **/<BR>/*********************************************************************/<BR>/**  Author          : Sakunamary Xiao                       **/<BR>/**  Create date     : 25 nov ,2006                            **/<BR>/**  version         : 1.0                                     **/<BR>/**  description     : this program is for the user who can not get **/<BR>/**              the correct value from function today(). this pro- **/<BR>/**              will generate three macro variables :&amp;today_date   **/<BR>/**              &amp;today and &amp; date.these three varialbes layout is: **/<BR>/**                 name     : value                                **/<BR>/**              &amp;today_date : 25Nov2006                            **/<BR>/**              &amp;today      : "25Nov2006"d                         **/<BR>/**              &amp;date       : 20061125                             **/<BR>/*********************************************************************/<BR>dm out 'cls';<BR>options noxwait;<BR>/*** set the temp data to get the system date ***/<BR>data temp;<BR>x=1;<BR>run;<BR>/*** output to a temp text file to covertion  ***/</P>
<P>proc printto print="c:\today.txt";quit;<BR>proc print data=temp;run;<BR>proc printto;quit;</P>
<P>data _null;<BR>infile "c:\today.txt";<BR>input time $109-126;<BR>if _n_ = 1 ;<BR>month = substr(time,1,3);<BR>day   = substr(time,10,2);<BR>year = substr(time,14,4);<BR>date = compress(day||month||year);<BR>call symput('today_date',date);<BR>call symput('today',compress('"'||date||'"'||'d'));<BR>call symput('date',put(&amp;today.,yymmddn8.));<BR>run;<BR>/*** clean up the temp file ***/</P>
<P>data _null_;<BR>x ' del c:\today.txt';<BR>run;</P>
<P>proc sql;drop table temp;quit;<BR>dm out 'cls';<BR>/******* end of program   *********/</P>
<P><BR>/******* programe example  **************/<BR>*** get the last month last day;<BR>/*<BR>data _null_;<BR>call symput ("var1",put(intnx("month",&amp;today.,-1,"end"),yymmddn8.));<BR>call symput ("var2",put(intnx("month",&amp;today.,-1,"end"),date9.));<BR>run;</P>
<P>the var1 value is 20061031.<BR>the var2 value is 31OCT2006.<BR>*/<BR></P>
二维码

扫码加我 拉你入群

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

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

2006-11-25 20:47:00
<P>公布一下源代码~~</P>
<P>整个程序的原理就是利用output中有显示正确的系统时间与日期,将正确的系统时间读进去然后再赋给macro变量。</P>
二维码

扫码加我 拉你入群

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

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

2006-11-27 14:47:00
<P>update the new version of today macro :</P>
<P>I check the sas system find that there is as system-generated view named sashelp.vmacro . in this view there is a macro variable named SYSDATE9. the value seem to be the system correct time .I find it in my company computer ,the SAS version is 9.1.3 and of course the software is not a XX version .If the macro variable can be found in SAS 8 XX version than the %toady() can be change to and very easy coding.</P>
<P>here is the %today() source code V2</P>
<P>%macro today();</P>
<P>%local today;</P>
<P>%let today = "&amp;sysdate9."d;</P>
<P>&amp;today</P>
<P>%mend;</P>

<P>this version macro can be use as function today like this :</P>
<P>xx=%today();</P>
<P>just the same as </P>
<P>xx=today();</P>

<P>Is it quite easy?</P>
二维码

扫码加我 拉你入群

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

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

2006-11-28 16:35:00
<P>这是第3次更新.改善了代码和修改了一个较大的BUG,这个程序要求SAS SESSION的生成时间较低.</P>
<P>%macro today(null);<BR>%local today ; <BR>%global time1 ;<BR>%local  time2;<BR>%local int;<BR>%if &amp;time1. =  %then %do ;<BR>      %let today = "&amp;sysdate9."d;<BR>            %let time1 = %sysfunc(date(),date9.);<BR>      %end;<BR>%else   %do ;<BR>  %let time2 = %sysfunc(date(),date9.);<BR>          %if %eval(%substr(&amp;time1.,1,2)) &gt; %eval(%substr(&amp;time2.,1,2)) <BR>                    %then %do;<BR>                            %put ERROR :The arguement of %totay() is out of range.;<BR>       %put NOTES :%Today() return the value of SAS session create date.;<BR>                            %let today = "&amp;sysdate9."d;<BR>                    %end;<BR>        %else %do; <BR>    %let int   = %sysfunc(intck(day,"&amp;time1"d,"&amp;time2"d));<BR>    %let today = %sysfunc(intnx(day,"&amp;sysdate9."d,&amp;int.),date9.);<BR>    %end;  <BR>  %end;</P>
<P>&amp;today<BR>%mend today ;</P>
二维码

扫码加我 拉你入群

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

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

-->
<P>依旧会运行程序占用系统资源。即便每天更新一次的话。改代码的效果会更好</P>
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群