Desktop productivity for business analysts and programmers

How to format a global variable

Reply
N/A
Posts: 0

How to format a global variable

I define a global variable as follows:
%let todaydate=today();
and SAS assign a number to the 'todaydate'. Anyone knows whether it is possible for me to format the 'todaydate', e.g. ddmmyy or ddmonyy etc?
Super User
Posts: 5,382

Re: How to format a global variable

Try

%let todaydate = %sysfunc(putn("&SYSDATE9"D,ddmmyy.));

Regards,
Linus
Data never sleeps
SAS Super FREQ
Posts: 8,818

Re: How to format a global variable

Hi:
If you DO want to use the today() function instead of &SYSDATE9, you can use it directly in the %LET, and with the TODAY() function, a second argument is allowed for %SYSFUNC that formats the returned date:
[pre]
%let d1 = %sysfunc(today(),ddmmyy.);
%let d2 = %sysfunc(today(),worddate.);
%let d3 = %sysfunc(today(),mmddyy10.);
%let d4 = %sysfunc(putn("&sysdate9"d ,mmddyyp10.));
%let d5 = %sysfunc(putn('01Jan2008'd ,weekdate.));

%put d1= &d1;
%put d2= &d2;
%put d3= &d3;
%put d4= &d4;
%put d5= &d5;
[/pre]

cynthia
N/A
Posts: 0

Re: How to format a global variable

Hihi,

just tried but sas still assign some other number to the date..
SAS Super FREQ
Posts: 8,818

Re: How to format a global variable

Hi:
&SYSDATE may not be the same date as TODAY(). Especially if your version of SAS is on a server that is not taken down often. Usually &SYSDATE is the date that the SAS session started...while TODAY() returns a value from the computer's "calendar/clock" functions.

Are you saying that today() does not return today's date????

[pre]
%let x = %sysfunc(today());
%let y = %sysfunc(today(),mmddyy10.);
[/pre]

If these statements do not produce the following results, then you should contact Tech Support for more help. (If you're on the other side of the international date line, of course, your date will be off from mine by a day.
[pre]
1 %let x = %sysfunc(today());
2 %let y = %sysfunc(today(),mmddyy10.);
3
4 %put *******x=&x y=&y;
*******x=17764 y=08/20/2008

[/pre]

Today's date in as a SAS number is 17764. With the mmddyy10. format applied, the macro variable &Y has a value of 08/20/2008.

cynthia
N/A
Posts: 0

Re: How to format a global variable

Hi..

I manage to get it already! Thanks so much for everybody's help.
\(^o^)/
Ask a Question
Discussion stats
  • 5 replies
  • 240 views
  • 0 likes
  • 3 in conversation