Help using Base SAS procedures

want to merge the two datas by year but error says they are different data types.

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

want to merge the two datas by year but error says they are different data types.

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!!


Accepted Solutions
Solution
‎04-24-2014 12:31 PM
Occasional Contributor
Posts: 10

Re: want to merge the two datas by year but error says they are different data types.

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


All Replies
PROC Star
Posts: 7,363

Re: want to merge the two datas by year but error says they are different data types.

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.

Frequent Contributor
Posts: 102

Re: want to merge the two datas by year but error says they are different data types.

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?

PROC Star
Posts: 7,363

Re: want to merge the two datas by year but error says they are different data types.

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

proc contents data=cshk13; run;

and

proc contents data=hk21; run;

Frequent Contributor
Posts: 102

Re: want to merge the two datas by year but error says they are different data types.

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!

PROC Star
Posts: 7,363

Re: want to merge the two datas by year but error says they are different data types.

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;

Solution
‎04-24-2014 12:31 PM
Occasional Contributor
Posts: 10

Re: want to merge the two datas by year but error says they are different data types.

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);

PROC Star
Posts: 7,363

Re: want to merge the two datas by year but error says they are different data types.

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.

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 289 views
  • 7 likes
  • 3 in conversation