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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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