BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_Forum
Calcite | Level 5

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(*) into:S1 from l;
select count(*) into:s2 from l2 where date="&maxdt.";
quit;

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You need this:

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

Ksharp

View solution in original post

5 REPLIES 5
Ksharp
Super User

You need this:

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

Ksharp

sas_Forum
Calcite | Level 5

Thqs Ksharp

manojinpec
Obsidian | Level 7

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

Ksharp
Super User

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

the same result will be .

Haikuo
Onyx | Level 15

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(*) into:S1 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(*) into:S1 from l;

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

quit;

Haikuo

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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