BookmarkSubscribeRSS Feed
Yennie
Calcite | Level 5
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!
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
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]
Yennie
Calcite | Level 5
Hi Cynthia!

I haven given this a try and this works awesome!

Cheers,
Yennie

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 717 views
  • 0 likes
  • 2 in conversation