BookmarkSubscribeRSS Feed
StickyRoll
Fluorite | Level 6

Issue when trying to achieve a dynamic SQL Where statement with a Macro Variable that contains symbol

 

I have a script to perform PROC SQL Update in which the Where statement (both left and right side of the Where statement) is dynamic.


However, I am getting this error:

ERROR: Function STRIP requires a character expression as argument 1.

The script as below.

%let in_dataset_aoc = land.pvcf;
%let out_dataset_aoc = work.pvcf2;

%let concat_str_aoc = strip(ENTITY_ID)||'#'||strip(REPORTING_DT)||'#'||strip(INSURANCE_CONTRACT_GROUP_ID)||'#'||strip(CASHFLOW_TYPE_CD)||'#'||strip(CURRENCY_CD);

data load_process;
	set &in_dataset_aoc.;
	format KEY $10000.;
	KEY = &concat_full_aoc.;
run;

proc sql noprint;
	select key, PV_RSK_ADJ_AMT, PV_BEL_AMT, PV_BV_BEL_AMT, PV_LIC_BEL_CUR_AMT, PV_LIC_BEL_PT_AMT, PV_LIC_RA_CUR_AMT, PV_LIC_RA_PT_AMT into :key_1-, :pv_rsk_adj_amt_1-, :pv_bel_amt_1-, :pv_bv_bel_amt_1-, :pv_lic_bel_cur_amt_1-, :pv_lic_bel_pt_amt_1-, :pv_lic_ra_cur_amt_1-, :pv_lic_ra_pt_amt_1-
	from load_process;
	
	select count(1) into :update_cnt
	from load_process;
quit;

%macro update_pvcf;
	%if &update_cnt. >= 1 %then %do;
		%do i = 1 %to &update_cnt.;
			proc sql; 
				update &out_dataset_aoc.
				set PV_RSK_ADJ_AMT = 1
				where &concat_full_aoc. = "&&key_&i..";
			quit;
		%end;
	%end;
%mend;

%update_pvcf;

What could be wrong here? the Macro Variable couldn't resolve in the Where statement? I tried quote and unquote but it still won't work.

H

3 REPLIES 3
LinusH
Tourmaline | Level 20

I don't see the declaration of concat_full_aoc.

Data never sleeps
PaigeMiller
Diamond | Level 26

However, I am getting this error:

ERROR: Function STRIP requires a character expression as argument 1.

 

This is not a macro error. This is a base SAS error where your STRIP function isn't working.

 

Agreeing with @Kurt_Bremser , first you need to get the code to work without macro variables on one instance. You have not done that. Once you get it to work, you will find it much easier to get it to work with macro variables. And if you don't have working SAS code, then it will never work with macros or macro variables. This is an extremely important point, but most people ignore this advice ... don't ignore this advice. Following this advice will not only help with this specific problem, but many many many problems in the future.

--
Paige Miller

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 3 replies
  • 950 views
  • 1 like
  • 4 in conversation