Adding date in variable name in SAS

606 views Asked by At

I have a column with name total transaction. I want to add a date 4 days back from now in its name .

For example if today is 20161220 so I want my variable to be renamed as total_transaction_20161216.

Please suggest me a way out of my problem.

1

There are 1 answers

0
Longfish On

Just create a macro variable that stores the required date format and then use that in a rename statement within proc datasets.

%let datevar = %sysfunc(intnx(day,%sysfunc(today()),-4),yymmddn8.);

%put &=datevar.;

data have;
total_transaction=1;
run;

proc datasets lib=work nolist nodetails;
modify have;
rename total_transaction = total_transaction_&datevar.;
quit;