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

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
  • 991 views
  • 0 likes
  • 4 in conversation