I am struggling with this compress function in the code below that I am trying to convert.
Old code: (This code works and returns the results below)
data _null_;
%let startdt='2015/11/1';
date_num=compress(&startdt,"'");
call symputx('date_num',date_num);
%put &startdt;
%put &date_num;
run;
This code returns values for the macro variable startdt as 2015/11/1 and datenum as 2015/11/1.
I am trying to achieve similar functionality using macro variables for dates.
New code: (This code gives me an error and I am not able to figure out why)
data _null_;
dt = date();
last_mth_beg = intnx('month',dt,-1,'beginning');
call symput('startdt',put(last_mth_beg,YYMMDDS10.));
date_num=compress(&startdt,"'");
call symputx('date_num',date_num);
%put &startdt;
%put &date_num;
run;
I am getting an error when I run this new code. I would like to get results as in the old code. Please help. Thank you!
%LETand%PUTstatements to either before or after your data step, since that is when SAS is going to evaluate them it makes your code easier to read and understand. Leaving them in the middle of the data step makes it look like they are some how being evaluated while the data step is running, which is not true. Does that fix your issue? - Tom%PUTstatements to after therun;statement. Otherwise they will generate an error that the macro variables don't exist or, perhaps worse, show you the values they had BEFORE the data step ran. - Tom