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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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