May I know how to overcome the below error?
SAS code:
proc sql noprint;
select
"FAULT_ID = "||compress(f_id)|| " ; "||" IF " || notupper(col_nm)|| " eq " || 0 || " and " || length(col_nm) || " eq " || 3 || " then output ; "
into :UPPERCASE
separated by " "
from oper_flt_ref
where category="UPPERCASE" and tbl_nm="INSURANCE";
quit;
Log:
26 proc sql noprint;
27 select
28 "FAULT_ID = "||compress(f_id)|| " ; "||" IF " || notupper(col_nm)|| " eq " || 0 || " and " || length(col_nm) ||
28 ! " eq " || 3 || " then output ; "
29 into :UPPERCASE
30 separated by " "
31 from oper_flt_ref
32 where category="UPPERCASE" and tbl_nm="INSURANCE";
ERROR: Concatenation (||) requires character operands.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
33 quit;
0 and 3 are numbers; enclose them in quotes to make them strings.
You have to ask this question after 900 posts here? Really?
Sometimes I feel like talking to a brick wall.
"length)col_nm)" result into a number.
Try to replace it into: "put(length(col_nm), 4. )" /* adapt length as need - 4 digits or ...? */
@Shmuel wrote:
"length)col_nm)" result into a number.
Try to replace it into: "put(length(col_nm), 4. )" /* adapt length as need - 4 digits or ...? */
notupper(col_nm)
will cause the same problem.
Using the cats() function (which automatically converts) should fix it.
@Babloo wrote:
Where to use cats function?
TRY:
select
cats("FAULT_ID = ", compress(f_id), " ; IF ", notupper(col_nm), " eq 0 and ",
length(col_nm), " eq 3 then output ; ")
.......
I'm not sure that the SAS code written to macro variable UPPERCASE would be very useful if it contained comparisons of two constants (such as "5 eq 0" or "3 eq 3"). So, maybe quoting the whole function call "length(col_nm)" (same with notupper) would come closer to what @Babloo needs.
Thinking about it, this is not good at all. Instead of feeding a lot of code into a macro variable (which will sooner or later exceed the 64K limit of macro variables), this should be done in a data step with call execute.
But this all exceeds @Babloo's SAS skills by orders of magnitude, so he/she should refrain from wasting time with this and instead try to learn the SAS basics.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.