DATA Step, Macro, Functions and more

Macro Variable Help

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

Macro Variable Help

I have been away from SAS for about 5 years and for the life of me I cannot figure out why even though the marcrovar appears to resolve correctly, it is not working.  Below are examples if I use the macrovar - error, if I explicitly type '2016' i get results.  I am sure I have just forgotton something very basic, but I am really stumped.

 

1544 options ls=250 nocenter macrogen symbolgen source;
1545
1546 %let d1=%eval(%sysfunc(today()));
1547 %let d1a=%sysfunc(putn(&d1,mmddyy10.));
SYMBOLGEN: Macro variable D1 resolves to 20481
1548 %let enddate = %eval(%sysfunc(intnx(week,&d1,0))+6);
SYMBOLGEN: Macro variable D1 resolves to 20481
1549 %let enddatea=%sysfunc(putn(&enddate,mmddyy10.));
SYMBOLGEN: Macro variable ENDDATE resolves to 20483
1550 %let begdate = %eval(&enddate-364);
SYMBOLGEN: Macro variable ENDDATE resolves to 20483
1551 %let begdatea=%sysfunc(putn(&begdate,mmddyy10.));%put &begdatea;
SYMBOLGEN: Macro variable BEGDATE resolves to 20119
SYMBOLGEN: Macro variable BEGDATEA resolves to 01/31/2015
01/31/2015
1552 %let year1=%eval(%sysfunc(intnx(year,&d1,-1)));
SYMBOLGEN: Macro variable D1 resolves to 20481
1553 %let year2=%eval(%sysfunc(intnx(year,&d1,0)));
SYMBOLGEN: Macro variable D1 resolves to 20481
1554 %let firstyear=%str(%')%sysfunc(putn(&year1,year4.))%str(%');%put &firstyear=;
SYMBOLGEN: Macro variable YEAR1 resolves to 20089
SYMBOLGEN: Macro variable FIRSTYEAR resolves to '2015'
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
'2015'=
1555 %let curryear=%str(%')%sysfunc(putn(&year2,year4.))%str(%');%put &curryear=;
SYMBOLGEN: Macro variable YEAR2 resolves to 20454
SYMBOLGEN: Macro variable CURRYEAR resolves to '2016'
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
'2016'=

 

data itemdata(drop=ohdr_demand ohdr_qty ohdr_lines ohdr_margin)
1511 orddata(drop=item_status_at_order demandafterdisc demandcost demandmargin demandqty swki findings chains seedbeads gwp);
1512 set out1.itemdata;
1513 *if sales_year = '2016';
1514 if sales_year = &curryear;
SYMBOLGEN: Macro variable CURRYEAR resolves to '2016'
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
NOTE: Line generated by the macro variable "CURRYEAR".
1 '2016'
-
390
-
200
ERROR 390-185: Expecting an relational or arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

1515 if substr(curr_cat,2,1) = 'K' and substr(curr_cat,4,1) = 'A' and put(shipped_item,$swrgwp.) = 'NOT SWRGWP' then swki = 1;else swki = 0;
1516 if substr(curr_cat,1,1) = 'M' then findings = 1;else findings = 0;
1517 if substr(curr_cat,1,1) = 'H' then chains = 1;else chains = 0;
1518 if substr(curr_cat,1,1) = 'E' then seedbeads = 1;else seedbeads = 0;
1519 if put(shipped_item,$gwpmat.) not in ('NOT GWP') then gwp = 1;else gwp = 0;
1520 cust_type = current_cust_type_at_eom;
1521 if cust_type = ' ' then cust_type = current_cust_type;
1522 if cust_type = ' ' then cust_type = cust_type_at_eom;
1523 if cust_type = ' ' then cust_type = cust_type_at_time_of_order;
1524 weekend=intnx('week',datepart(ord_mail_dt),0)+6;
1525 format weekend mmddyy10.;
1526 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.ITEMDATA may be incomplete. When this step was stopped there were 0 observations and 26 variables.
WARNING: Data set WORK.ITEMDATA was not replaced because this step was stopped.
WARNING: The data set WORK.ORDDATA may be incomplete. When this step was stopped there were 0 observations and 20 variables.
WARNING: Data set WORK.ORDDATA was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.03 seconds


1527 data itemdata(drop=ohdr_demand ohdr_qty ohdr_lines ohdr_margin)
1528 orddata(drop=item_status_at_order demandafterdisc demandcost demandmargin demandqty swki findings chains seedbeads gwp);
1529 set out1.itemdata;
1530 if sales_year = '2016';
1531 *if sales_year = &curryear;
1532 if substr(curr_cat,2,1) = 'K' and substr(curr_cat,4,1) = 'A' and put(shipped_item,$swrgwp.) = 'NOT SWRGWP' then swki = 1;else swki = 0;
1533 if substr(curr_cat,1,1) = 'M' then findings = 1;else findings = 0;
1534 if substr(curr_cat,1,1) = 'H' then chains = 1;else chains = 0;
1535 if substr(curr_cat,1,1) = 'E' then seedbeads = 1;else seedbeads = 0;
1536 if put(shipped_item,$gwpmat.) not in ('NOT GWP') then gwp = 1;else gwp = 0;
1537 cust_type = current_cust_type_at_eom;
1538 if cust_type = ' ' then cust_type = current_cust_type;
1539 if cust_type = ' ' then cust_type = cust_type_at_eom;
1540 if cust_type = ' ' then cust_type = cust_type_at_time_of_order;
1541 weekend=intnx('week',datepart(ord_mail_dt),0)+6;
1542 format weekend mmddyy10.;
1543 run;

NOTE: There were 11415407 observations read from the data set OUT1.ITEMDATA.
NOTE: The data set WORK.ITEMDATA has 575080 observations and 26 variables.
NOTE: The data set WORK.ORDDATA has 575080 observations and 20 variables.
NOTE: DATA statement used (Total process time):
real time 6.87 seconds
cpu time 6.48 seconds

 


Accepted Solutions
Solution
‎01-28-2016 12:06 PM
Super User
Posts: 19,861

Re: Macro Variable Help

Don't include quotes in your macro variable, add them in the code.

 

 

%let cur_year=2016;

...
if year = "&cur_year";

View solution in original post


All Replies
Solution
‎01-28-2016 12:06 PM
Super User
Posts: 19,861

Re: Macro Variable Help

Don't include quotes in your macro variable, add them in the code.

 

 

%let cur_year=2016;

...
if year = "&cur_year";
Contributor
Posts: 43

Re: Macro Variable Help

perfect -thank you  -I guess I was overthinking it...

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 206 views
  • 0 likes
  • 2 in conversation