BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathiskumar_D
Obsidian | Level 7
%macro accountreport(State=);
proc sql;
title "&title";
create table mydata as
select Acct_ID,Name,birthday format ddmmyy8.0,Sex,State format $char8.,Cust_Type,Product,Balance,Last_Tran_Date=symget('tran_date')
from myprj2.profile2;
quit;
%mend accountreport;

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

proc content of the data is attached..

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
  1. always make sure that your Base SAS code works before putting it in a macro
  2. your macro is totally useless, as the macro parameter is never used in the macro, therefore remove the macro definition. You don't need it.
  3. this causes your problem:
Last_Tran_Date=symget('tran_date')

When used in the select (and not in a where), it will result either in a zero (condition not met) or a 1 (condition is met).

BUT: last_tran_date is numeric, while the result of the symget() function is always of type character, and proc sql does not do type conversions on the fly (as the data step does), so this can't work.

You need to convert the result of your symget() to a proper SAS date value, and I guess you wanted this condition to be part of a where clause. How you convert depends on the contents of &tran_date.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User
  1. always make sure that your Base SAS code works before putting it in a macro
  2. your macro is totally useless, as the macro parameter is never used in the macro, therefore remove the macro definition. You don't need it.
  3. this causes your problem:
Last_Tran_Date=symget('tran_date')

When used in the select (and not in a where), it will result either in a zero (condition not met) or a 1 (condition is met).

BUT: last_tran_date is numeric, while the result of the symget() function is always of type character, and proc sql does not do type conversions on the fly (as the data step does), so this can't work.

You need to convert the result of your symget() to a proper SAS date value, and I guess you wanted this condition to be part of a where clause. How you convert depends on the contents of &tran_date.

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 859 views
  • 0 likes
  • 2 in conversation