DATA Step, Macro, Functions and more

Date Macros conversion

Reply
Frequent Contributor
Frequent Contributor
Posts: 78

Date Macros conversion

 

%let   cutdt = '01jan2011'd ;

 

I would like to get a macro value as    01Jan2011   or    Jan 01, 2011       from  &cutdt .  

 

Is there any converted function ?

 

Thank you very much .

SAS Employee
Posts: 17

Re: Date Macros conversion

Try this -

 

%let cutdt=01jan2011 ;
proc print data = sashelp.cars (obs=10);
title "%upcase(&cutdt)";
run;

SAS Super FREQ
Posts: 708

Re: Date Macros conversion

Hi

 

I recommend to store just the date as DATE9. value in a macro variable. From there all sorts use uses are possible.

 

Have a look at the sample code below.

 

%let cutdt = 01jan2011;

* use as date constant ;
data want;
  somedate = "&cutdt"d;
  format someDate worddate.;
run;

* a new formatted date value as text;
%let newDate = %sysfunc( putn(%sysevalf("&cutdt"d), ddmmyyp10.));
title "Date as of &newDate";
proc print data=want;
run;

Bruno

Super Contributor
Posts: 440

Re: Date Macros conversion

You can do the conversion in a datstep:

 

%let   cutdt = '01jan2011'd ;

data _null_;
        dt=&cutdt;
        call symput ('date1', put(dt, date9.));
        call symput ('date2', put(dt, worddate12.));
run;

%put &=date1;
%put &=date2;

I believe %SYSFUNC could also be used, bypassing the datastep, but an example doesn't comes to mind.

 

Hope this helps,

- Jan.

Frequent Contributor
Frequent Contributor
Posts: 78

Re: Date Macros conversion

Posted in reply to jklaverstijn
Thank you , all, very much, for your help !
Ask a Question
Discussion stats
  • 4 replies
  • 284 views
  • 1 like
  • 4 in conversation