BookmarkSubscribeRSS Feed
Geo-
Quartz | Level 8

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;
5 REPLIES 5
novinosrin
Tourmaline | Level 20
%let month= %sysfunc(month("&date01"d));
%let year= %sysfunc(year("&date01"d));
Geo-
Quartz | Level 8

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;

novinosrin
Tourmaline | Level 20


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 

Reeza
Super User

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. 

 

 

2A7B2DBF-A05A-4DB5-84C4-B3F985E4F30B.jpeg

 


@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;

 

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1552 views
  • 0 likes
  • 4 in conversation