BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

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;
8 REPLIES 8
Shmuel
Garnet | Level 18

"length)col_nm)"  result into a number.

Try to replace it into:  "put(length(col_nm), 4. )"  /* adapt length as need - 4 digits or ...? */

 

Kurt_Bremser
Super User

@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
Rhodochrosite | Level 12
Where to use cats function?
Shmuel
Garnet | Level 18

@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 ; ")
  .......
FreelanceReinh
Jade | Level 19

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.

Kurt_Bremser
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2931 views
  • 3 likes
  • 4 in conversation