Help using Base SAS procedures

Date Format. Help!

Reply
Frequent Contributor
Posts: 78

Date Format. Help!

Hi People!

I have this tiny macro that says
%Let MonYear = %sysfunc(putn(%sysfunc(intnx(Month,%sysfunc(date()),+0)),date5.));

Data MyTable_&Monyear.;
Set ABCTable;
Run;

I am hoping to get the date format as MyTable_Feb2010 (which is today's date). Do you guys know how to change this macro script around?

also... What about... in another way... if I want it to be Mytable1002 instead where 10 is the year and 02 is the month, then how should the script be???

Hoping you guys can help me out on this one!

Cheers!
SAS Super FREQ
Posts: 8,740

Re: Date Format. Help!

Hi:
If you look at the documentation,
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/z3514sysfunc.htm#a000384574
you will see that one of the arguments to %SYSFUNC is a format for a date variable. (As shown in the example, entitled ""Formatting the Current Date in a TITLE Statement.) But, even though the doc shows the example in a title statement, it would work in other situations, such as creating a filename.

The SAS log from using %SYSFUNC as shown in the documentation is shown below.

cynthia
[pre]
2979 ** One of the arguments to %SYSFUNC is a format for a date;
2980 %let monyear = %sysfunc(date(),monyy5.);
2981 %let yymm = %sysfunc(date(),yymmdd4.);
2982
2983 ** Use the macro variables with formats to create the file name;
2984 %let fname1 = MyTable_&monyear;
2985 %let fname2 = MyTable&yymm;
2986
2987 ** %PUT statements to show the file name;
2988 %put monyear= &monyear fname1= &fname1;
monyear= FEB10 fname1= MyTable_FEB10
2989 %put yymm = &yymm fname2=&fname2;
yymm = 1002 fname2=MyTable1002

[/pre]
Frequent Contributor
Posts: 78

Re: Date Format. Help!

Hi Cynthia!

I haven given this a try and this works awesome!

Cheers,
Yennie
Ask a Question
Discussion stats
  • 2 replies
  • 137 views
  • 0 likes
  • 2 in conversation