where c.State = ' " ST +(-1) " '. What's this?

Posts: 68

where c.State = ' " ST +(-1) " '. What's this?

Hi guys,

Given the following two data sets:

  • CUSTOMERS - containing the variables Customer_ID and State
  • ORDERS - containing a variable holding the order's total price called Total and Customer_ID

The following SAS program is submitted:

proc sql;

  create table WORK.STATES as select distinct State as ST from CUSTOMERS;


data _null_;

  set WORK.STATES end=eof;

  file "c:\Projects\StReports.sas";

  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;";

  put "quit;";

  if not eof then put;


%include "c:\Projects\StReports.sas" / source2;

Super User
Super User
Posts: 8,075

Re: where c.State = ' " ST +(-1) " '. What's this?

Pointer Control

SAS(R) 9.3 Statements: Reference

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. ;

Ask a Question
Discussion stats
  • 1 reply
  • 1 like
  • 2 in conversation