LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 23 Feb 2006 17:07:47 -0500
Reply-To:     Pavlo Row <pavlo@INORBIT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Pavlo Row <pavlo@INORBIT.COM>
Subject:      Re: Hoiw to stopr from printing into output SAS window
Content-Type: text/plain; charset="iso-8859-1"

Hi everyone, This problem with the log filling up, David C. is probbaly quite right. Something maybe a little off with the code a very generous person did for me on this site. I post below the original message I placed here a couple of weeks ago. A poster solved my problem, the code (the macro) works correctly, it does what is supposed to do, except I get this stuff in the LOG window and I can't complete the process. So, here is the message. I hope I can get help or else I will get burned here. Rememebr that it will atke me a lot of time to be typing long field names. So his macro works for me because it is very automated. Except, for this log window nuisance. Thanks. pavlo

------------------------------------------------------------------------------------------------------------- * Subject: SAS Data Step as prelude to logistic modeling

Hello All,

Please copy and paste the following example data set. In this example data set I have a MONTH field (MONTH takes on only APRIL & MAY 2005 values), a unique identifier, ID, TARGET variable (takes on NO/YES or 0/1 representing customer response to MAY 2005 campaign). Next I show only three fields out of very many fields like 400 fields or so. I chose three representative fields to show here: # of credit cards customer had in APRIL and MAY 2005, customer bank balance in APRIL and MAY 2005, and the # of months the customer had lived in his house in APRIL & MAY 2005. Again, in the real data set I have many such fields.;

data foo; input MONTH $ ID TARGET NUM_CREDIT_CARDS BALANCE MONTHS_RESIDENCE; cards; APR05 1 . 1 57103 24 MAY05 1 0 2 1516 25 APR05 2 . 2 2468 92 MAY05 2 0 1 309 93 APR05 3 . 1 7672 74 MAY05 3 0 0 0 . APR05 4 . 1 53073 127 MAY05 4 1 1 6379 128 APR05 5 . 4 24894 36 MAY05 5 0 0 9859 37 APR05 6 . 0 12 164 MAY05 6 0 1 1699 165 APR05 7 . 2 30248 24 MAY05 7 1 3 1625 25 APR05 8 . 2 45516 345 MAY05 8 1 1 591 346 APR05 9 . 2 5391 216 MAY05 9 0 3 6262 217 APR05 10 . 2 4857 252 MAY05 10 1 0 14457 . ; run;

* I use the above example data set to compute additional fields which I call DIFF1 & AVG1, DIFF2 & AVG2, DIFF3 & AVG3, ..., DIFF400 & AVG400 (400 since I have 400 such numeric fields)

If you run the following code it will become clear how I come up with these fields. For DIFF1, for example, I just take the difference between MAY and APRIL and I assign the answer to MAY becasue that's where I have the TARGET variable populated. Later Once I compute DIFF1 & AVG1, etc., I will delete APRIL and I will be left with only MAY. Then I can build a logistic model based on DIFF1 & AVG1, etc.;

data TEST(drop=TEMP1-TEMP3); set foo; by ID; if last.ID then temp1=NUM_CREDIT_CARDS;

DIFF1=temp1-lag(NUM_CREDIT_CARDS);

AVG1=(temp1+lag(NUM_CREDIT_CARDS))/2; if last.ID then temp2=BALANCE; DIFF2=temp2-lag(BALANCE); AVG2=(temp2+lag(BALANCE))/2; if last.ID then temp3=MONTHS_RESIDENCE;

DIFF3=temp3-lag(MONTHS_RESIDENCE);

AVG3=(temp3+lag(MONTHS_RESIDENCE))/2; run;

* This is my question: How can I automate the above step? I mean, can you imagine sitting here typing the above lines many times:

DIFF1=temp1-lag(NUM_CREDIT_CARDS) AVG1=(temp1+lag(NUM_CREDIT_CARDS))/2

DIFF2=temp2-lag(BALANCE) AVG2=(temp2+lag(BALANCE))/2 . . . DIFF400=temp400-lag(BALANCE) AVG400=(temp400+lag(BALANCE))/2

Again, the answer fields DIFF1=temp1-lag(BALANCE) AVG1=(temp1+lag(BALANCE))/2 and so on will be used in logistic modeling.

Thanks.

pavlo

Pavlo:

Here is the code of the automation and output follows it. Here I use DIFF4-DIFF6 and AVG4-AVG6 for statistics for fields 4-6, numeric fields, for calculation of difference and average instead of DIFF1-DIFF3 and AVG1-AVG3 in the last code. It is also assumed that fields beginning with field number 4 are for difference and average calculation. If not, you will need to rearrange the fields. Let me know if you have problems with the code or result. Have fun with it. Actually I enjoyed and learned more macro from this coding.;

options nomprint nomlogic nosymbolgen; data foo; input MONTH $ ID TARGET NUM_CREDIT_CARDS BALANCE MONTHS_RESIDENCE; cards; APR05 1 . 1 57103 24 MAY05 1 0 2 1516 25 APR05 2 . 2 2468 92 MAY05 2 0 1 309 93 APR05 3 . 1 7672 74 MAY05 3 0 0 0 . APR05 4 . 1 53073 127 MAY05 4 1 1 6379 128 APR05 5 . 4 24894 36 MAY05 5 0 0 9859 37 APR05 6 . 0 12 164 MAY05 6 0 1 1699 165 APR05 7 . 2 30248 24 MAY05 7 1 3 1625 25 APR05 8 . 2 45516 345 MAY05 8 1 1 591 346 APR05 9 . 2 5391 216 MAY05 9 0 3 6262 217 APR05 10 . 2 4857 252 MAY05 10 1 0 14457 . ; run;

*proc print; *run;

proc sql noprint; select name into :ColumnName separated by ' ' from dictionary.columns where libname='WORK' and memname='FOO'; select count(name) into :ColumnCount from dictionary.columns where libname='WORK' and memname='FOO'; quit;

%let ColumnCount=%trim(%left(&ColumnCount));

%macro namelist(name=,count=); %do i=1 %to &count; %global Col&i; %let Col&i=%scan(&name,&i); %put &&Col&i; %end; %mend namelist;

%namelist(name=&ColumnName,count=&ColumnCount);

%let BegNumCol=4;

%macro Begset(); %do i=&BegNumCol %to &ColumnCount; %str(Temp&i=&&Col&i;); %end; %mend Begset;

%begset;

%macro Endset(); %do i=&BegNumCol %to &ColumnCount; %str(AVG&i=(Temp&i+&&Col&i)/2;); %str(DIFF&i=&&Col&i-Temp&i;); %end; %mend Endset;

%endset;

data Result(keep=ID MONTH TARGET DIFF&BegNumCol-DIFF&ColumnCount AVG&BegNumCol-AVG&ColumnCount); retain ID MONTH TARGET DIFF&BegNumCol-DIFF&ColumnCount AVG&BegNumCol-AVG&ColumnCount TEMP&BegNumCol-TEMP&ColumnCount; array D(&BegNumCol:&ColumnCount) DIFF&BegNumCol-DIFF&ColumnCount; array A(&BegNumCol:&ColumnCount) AVG&BegNumCol-AVG&ColumnCount; array T(&BegNumCol:&ColumnCount) TEMP&BegNumCol-TEMP&ColumnCount; set foo; by ID; if first.ID then do; %Begset; end; else do; %EndSet; output; end; put NUM_CREDIT_CARDS= BALANCE= MONTHS_RESIDENCE=; put T(4)= T(5)= T(6)=; run;

*proc print data=result; *run; -------------------------------------------------------------------------------------------------------------

-- ___________________________________________________ Play 100s of games for FREE! http://games.mail.com/


Back to: Top of message | Previous page | Main SAS-L page