BookmarkSubscribeRSS Feed
harshalshah
Calcite | Level 5

libname bci "/department/gld/uk/shahha03";
libname pdlref "/department/gld/uk/HK_MANNINGS_DC/pdl/ref/" ;
%macro bci_period(start_wk,end_wk);
data _null_;
set pdlref.time_cycle;
if week_id= &start_wk then do;
call symput("id_start",time_pd);
end;
if week_id = &end_wk then do;
call symput("id_end",time_pd);
end;
run;
%put &id_start &id_end;
%put &id_start &id_end;
data _null_;
set pdlref.time_cycle;
format week_id_end yymmddn8.;
id_end1 = &id_end+1;
do i = &id_start to &id_end;
id_end1 = id_end1 -1;
if time_pd = id_end1 then do;
call symput(cat('wkno',i),week_id);
call symput (cat('wkedno',i),PUT(week_id_end,YYMMDDn8.));
end;
end;
run;

%mend;


%macro bci_mnn;
%do i = &id_start %to &id_end;
%let wk=&&wkno&i;
%let wk1 =&&wkedno&i;
%put &wk1;
%let fileloc=/department/gld/uk/HK_MANNINGS_DC/rawdata/input/wk&&wk/original;
filename bci_mnn PIPE "zcat &fileloc./bci_mnn_&wk1.000000.dat.gz";
/*%let wk2 = cat('bci_mnn_',&wk1,'000000');*/
data work.bci_mnn_&wk (compress=yes);
length
retailer_basket_id $ 9
retailer_store_number $ 6
retailer_loyalty_card_id $ 13
retailer_coupon_id $ 13
retailer_promotion_id $ 6
time_key $ 8    
member_group_code $ 17 
member_group_code_type $ 1
coupon_printed $ 1
;
infile bci_mnn dsd missover dlm='|' end=eof;
/*infile "&fileloc./bci_mnn_&wk1.000000.dat" dsd missover dlm='|' end=eof;*/
input
retailer_basket_id $
retailer_store_number $
retailer_loyalty_card_id $
retailer_coupon_id $
retailer_promotion_id $
time_key $
member_group_code $
member_group_code_type $
coupon_printed $
;
week_id = &wk;
run;

proc sql noprint;
create table bci.BCI_MNN_&wk as
select bsk.*,cust.retailer_household_id from work.bci_mnn_&wk as bsk left join pdlref.customer as cust on bsk.retailer_loyalty_card_id = cust.retailer_identifying_card_id;
quit;
%end;
%mend;


%macro bci_yyyyww;
%let startwk =201425;
%let endwk =201428;
%bci_period(&startwk,&endwk);
%bci_mnn;
%mend;
%bci_yyyyww;

WARNING: Apparent symbolic reference ID_START not resolved.

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

       &id_start

ERROR: The %FROM value of the %DO I loop is invalid.

WARNING: Apparent symbolic reference ID_END not resolved.

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

       &id_end

ERROR: The %TO value of the %DO I loop is invalid.

ERROR: The macro BCI_MNN will stop executing.

While I apply macro variable inside %macro bci_period(start_wk,end_wk);

%bci_mnn;

%mend;

Program running fine and resolve this issue..can anyone says why call symput (ID_start & ID_end) value may not able to resolve...my question here if I created loop macro variable using call symput which is easily coming  during the program even though did not modify any syntax..

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would suggest that this condition:

if week_id= &start_wk then do;

doesn't resolve at any point to be true, hence the call symput is not run and ID_START is never defined.  The likelihood is that the call:

%let startwk =201425;

%let endwk =201428;

%bci_period(&startwk,&endwk);

when looked in combination with the if statement resolves to:

if week_id=201425 then do;

Which doesn't work.  If your sure that week_id is character and contains a value for 201425, then put quotes around the macro variable and retry:

if week_id="&start_wk." then do; 

This should then find a row.

However if week_id is numeric then you may need to convert it to the numeric type of week_id, e.g.

if put(week_id,yymm6.) = "&start_wk." then do;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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