DATA Step, Macro, Functions and more

Reg Date Macro

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 140
Accepted Solution

Reg Date Macro

Actually i am having two tables and check the counts of two datasets based on dates i am doing in this way but i ma getting

ERROR: Expression using equals (=) has components that are of different data types.
How can i check the counts

data l;
input id date date9.;
format date date9.;
cards;
2 13jan2012
2 13jan2012
2 13jan2012
run;

data l2;
input id date date9.;
format date date9.;
cards;
2 12jan2012
2 12jan2012
2 12jan2012
2 13jan2012
2 13jan2012
2 13jan2012
;
run;

proc sql;
select max(date) format=date9. into:maxdt  from l2;
quit;


proc sql;
select count(*) intoSmiley Frustrated1 from l;
select count(*) into:s2 from l2 where date="&maxdt.";
quit;

ERROR: Expression using equals (=) has components that are of different data types.


Accepted Solutions
Solution
‎04-10-2012 03:48 AM
Super User
Posts: 10,023

Re: Reg Date Macro

Posted in reply to sas_Forum

You need this:

select count(*) into:s2 from l2 where date="&maxdt."d ;

Ksharp

View solution in original post


All Replies
Solution
‎04-10-2012 03:48 AM
Super User
Posts: 10,023

Re: Reg Date Macro

Posted in reply to sas_Forum

You need this:

select count(*) into:s2 from l2 where date="&maxdt."d ;

Ksharp

Frequent Contributor
Posts: 140

Re: Reg Date Macro

Thqs Ksharp

Frequent Contributor
Posts: 139

Re: Reg Date Macro

Posted in reply to sas_Forum

i guess .(dot) after maxdt is not required.Not sure incase i am wrong

Super User
Posts: 10,023

Re: Reg Date Macro

Posted in reply to manojinpec

You are right. It doesn't matter whether the dot is there.

the same result will be .

Respected Advisor
Posts: 3,156

Re: Reg Date Macro

Posted in reply to sas_Forum

Another approach, not as slick of course, is to remove 'format=' and convert the date variable into numeric digits.

proc sql;

select max(date) into:maxdt from l2;

quit;

proc sql;

select count(*) intoSmiley Frustrated1 from l;

select count(*) into:s2 from l2 where date=input("&maxdt.",20.);

quit;

Or keep the format and then use informat to convert:

proc sql;

select count(*) intoSmiley Frustrated1 from l;

select count(*) into:s2 from l2 where date=input("&maxdt.",date9.);

quit;

Haikuo

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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