04-10-2012 02:28 PM
Attached file is an example (smaller size) of my dataset.
Columns A - E: Customer ID and address to send the promotion to.
Columns J & K: Each range set is for a different promotion. Only the customers in the range are eligible for the promotion.
I would like to create a dataset that, for each given range, SAS will look at the data in columns A-E and produce a table/results of only the customer ids in that range. Note: The Customer ID Range List and Customer Information are in two different datasets.
Any help is appreciated!
04-11-2012 11:56 AM
providing sample data (a data step with datalines) makes answering these types of questions so much easier...then we can just plug it into our SAS editor and fool with it until we get what seems like a solution. Also, we can then provide code that runs without errors...instead of just guessing...
04-11-2012 08:39 PM
In fact, this suggestion is one of the things I show in the paper that I co-authored with Renee Harper on how to make the best use of the SAS Community Forums. Just posted online:
04-11-2012 08:55 PM
This response is for Jay@TxOAG.
I don't know how to take your response.
I posted this because I don't know where to start. I have not written the program, hence why I didn't include the "data steps with datalines". I thought if I posted a sample of what my dataset looks like, maybe I can get some suggestions on how to approach the problem.
04-11-2012 10:05 PM
04-11-2012 11:49 PM
Try this...Hope it helps..
input customer_ID range;
data fmt (keep=FMTNAME START END LABEL TYPE);
length FMTNAME $30. START END $256.;
FMTNAME = 'Range' ;
START = Customer_ID ;
END = Range;
LABEL = 'Range';
TYPE = 'N' ;
proc format cntlin=fmt lib=work; run;
data customer;length x $20.;
input Customer_ID House_No Street_Name $ 25-39 City $ 40-55 State $ 56 -60;
170927308313 123 Elks Grove Chicago IL
171540339727 456 Crab Lake Baltimore MD
170060423416 7890 Winery Lane Frederick MD
170869014929 2468 Lombardi Drive San Francisco CA
111870069510 13579 PCH San Diego CA
165019812149 22226 Reunion Blvd Dallas TX
172270371229 11597 Gulf Drive Tampa Fl
proc print data=customer ;
04-12-2012 07:28 AM
My comment about "data step with datalines" or as @shiva used "cards", was to provide sample data. Although, there are certainly times when uploading a file is the only way to go, providing sample data in your question makes it easier for those of us with less time to devote to answering questions.
My mistake for not being more clear...
04-12-2012 12:04 AM
I would like to share 3 approaches that I've tried to answer your question.
|170869014929||2468||Lombardi Drive||San Francisco||CA|
2. Customer_Range (I modified the values to easily see what gets extracted)
1. Create a 'Summary' dataset merging both datasets, much like an outer join.
create table summary as
from Customer_Info, Customer_Range
2. Use DATA step to do the extract of intended data and output to another dataset.
if Customer_ID ge Customer_ID_L and Customer_ID le Customer_ID_H then output;
drop Customer_ID_L Customer_ID_H;
2nd approach (Use Call Execute)
1. The main logic is to iterate through the Customer_Range dataset, i.e. per observation, comparing the Customer_ID from Customer_Info dataset, to the range. The set of record that results to true condition is extracted to TEMP dataset. Afterwhich, PROMOTED dataset consolidates all data for all ranges.
if Customer_ID ge '||Customer_ID_L||' and Customer_ID le '||Customer_ID_H||' then output;
proc append base=Promoted
You can study Call Execute through http://www2.sas.com/proceedings/sugi22/CODERS/PAPER86.PDF and other sources on the web.
3rd approach (Use macro facility)
1. Create macro variables for count of observations in the Customer_Range and for the actual range values.
proc sql noprint;
select catt(count(1)) into :CustRange_Cnt from Customer_Range;
select Customer_ID_L format 13., Customer_ID_H format 13.
2. Main logic is much similar to 2nd approach. The main difference is that in this process, the macro variables will then be used as values for count and fulfilling conditions.
%do i=1 %to &CustRange_Cnt;
if Customer_ID ge &&Customer_ID_L&i and Customer_ID le &&Customer_ID_H&i then output;
proc append base=promoted
You may study macro in http://www2.sas.com/proceedings/sugi29/243-29.pdf and other sources in the web.
*NOTE: for 2nd and 3rd approaches, you may need to add a check if PROMOTED dataset exists, then drop/delete it before your next run since I used PROC APPEND which will just append data from previously created one.
Hope this helps answer your question.