08-23-2014 05:35 PM
Given the following two data sets:
The following SAS program is submitted:
create table WORK.STATES as select distinct State as ST from CUSTOMERS;
set WORK.STATES end=eof;
put "proc sql;";
put " select c.State, c.Customer_ID, sum(o.total) as Purchases";
put " from CUSTOMERS as c";
put " inner join ORDERS as o";
put " on c.Customer_ID = o.Customer_ID";
put " where c.State = ' " ST +(-1) " ' "; I don't understand this part. What does +(-) mean? Where I can know more about its functions or theories related? Thank you.
put " group by c.State, c.Customer_ID;";
if not eof then put;
%include "c:\Projects\StReports.sas" / source2;
08-23-2014 06:32 PM
When you use PUT to write a variable SAS will automatically write a space after the value. The +(-1) moves the pointer back by one space so you can overwrite the space with something else. In this case the closing single quote so that the literal value generated from the value of the ST variable in the current data step does not contain an extra trailing space when it is compared to the value of STATE in the generated WHERE clause.
When, as in this case, you want to quote the value of a single variable you can use the $QUOTE. format with the : modifier.
put " where c.State = " ST :$quote. ;