proc sql;
select max(data_bsn_dt) into:date01 from tableA;
quit;
%put &date02;
print out:31DEC2017
%put year("&date01"d);
print out:year("31DEC2017"d)
I used code:year("&date01"d) to extract year or month before,but it does not work now..could some have time solve,thanks.
Even in the data step,it still not working..
data _nulll;
if year("&date01"d)=2017
then call execute('proc sql;
select * from tableB;');
run;
%let month= %sysfunc(month("&date01"d));
%let year= %sysfunc(year("&date01"d));
thank you for your answer..I want to let them work in the data step,like:
data _null_;
if year("&date01"d)=year("&date02"d)=year("&date03"d)
then...
run;
1 %let date01=31DEC2017;
2
3 data _nulll;
4 if year("&date01"d)=2017
5 then put 'ok';
6 run;
ok
NOTE: The data set WORK._NULLL has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time 0.34 seconds
works fine
Your PROC SQL is missing a QUIT but your code appears correct otherwise.
Are you sure that’s what your macro variable is resolving to? Sometimes it’s not formatted and I can see that causing issues. Given you haven’t specified a format I’m pretty sure that’s what’s happening here, see test below.
@Geo- wrote:
proc sql;
select max(data_bsn_dt) into:date01 from tableA;
quit;
%put &date02;
print out:31DEC2017
%put year("&date01"d);
print out:year("31DEC2017"d)
I used code:year("&date01"d) to extract year or month before,but it does not work now..could some have time solve,thanks.
Even in the data step,it still not working..
data _nulll; if year("&date01"d)=2017 then call execute('proc sql; select * from tableB;'); run;
Try:
proc sql;
select max(data_bsn_dt) into:date01 from tableA;
quit;
data _null_;
if year(&date01) = 2017
then call execute('proc sql; select * from tableB;');
run;
In your example, you are %PUTting variable &date02 for control, but you use &date01 later in the code. %put &date01 and inspect it.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.