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

743  proc sql;

744      create table cshk14 as

745      select a.*, b.*

746      from cshk13 as a, hk21 as b

747      where a.isin = b.isin and a.year = b.annualreportdate;

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

748  quit;

it seems year in a and annualreportdate in b are different data types. how can i fix this? thank you!!

1 ACCEPTED SOLUTION

Accepted Solutions
djmangen
Obsidian | Level 7

Seeing the results of the proc print will be most valuable, but in all likelihood you will need to extract the year from Annual Report Date.  Assuming that the annual report date values looks something like 25NOV2013 then I would do something like:

Attrib Report_Year length=8;

AnnualReportDate = right(AnnualReportDate);

Report_Year = substr(AnnualReportDate,9,4);

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

Both comparisons use the equal operator.  Review your data and discover the data types of isin in both datasets, as well as year and annualreportdate.  Also, while it may not have shown up as an error you received, look at annualreportdate to see if it is a date or a year.

aarony
Obsidian | Level 7

the annual reportdate is annual reportdate. i think the issue is the data type. do u know how i can check them and also align them?

art297
Opal | Level 21

I would start by running proc contents on both files. e.g.,

proc contents data=cshk13; run;

and

proc contents data=hk21; run;

aarony
Obsidian | Level 7

Thank you arthur for your kind reply.

this is what i get.

  AnnualReportDate    Char     12    $12.      $12.

  year      Num    8

i am a begginer user in sas (only 1+week of experience) and do not know how to mitigate this issue. could you let me know? thanks much!

art297
Opal | Level 21

You will have to look at the first 10 or so records to see what AnnualReportDate looks like.

I'd run something like the following and let us (the forum) see the result

:

proc print data=hk21 (obs=10);

  var AnnualReportDate;

run;

djmangen
Obsidian | Level 7

Seeing the results of the proc print will be most valuable, but in all likelihood you will need to extract the year from Annual Report Date.  Assuming that the annual report date values looks something like 25NOV2013 then I would do something like:

Attrib Report_Year length=8;

AnnualReportDate = right(AnnualReportDate);

Report_Year = substr(AnnualReportDate,9,4);

art297
Opal | Level 21

I'm going to wait making any suggestion until aarony shows us what the data look like.  Given that it is a 12 character field I wouldn't assume to know what it looks like.  And aarony will need to convert it into a number and will be able to do it all within the original proc sql call.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 2097 views
  • 7 likes
  • 3 in conversation