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 (August 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 20 Aug 2007 19:56:34 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: MAking my codes run for multiple products at ONCE
Comments: To: sas_datalover@YAHOO.COM
In-Reply-To:  <653180.98002.qm@web62207.mail.re1.yahoo.com>
Content-Type: text/plain; format=flowed

This should get you started:

Data FindDiff ; Set Have ; By Prod Id ;

Late = ( Dif( Date ) - Dif( Supply ) ) > 15 ; If ( First.ID ) Then Late = 0 ;

Run ;

Proc Freq Data = FindDiff ; Table Late ; Run ;

Toby Dunn

Two wrongs are only the beginning.

Success always occurs in private and failure in full view.

Experience is something you don't get until just after you need it.

From: Syb it <sas_datalover@YAHOO.COM> Reply-To: Syb it <sas_datalover@YAHOO.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: MAking my codes run for multiple products at ONCE Date: Mon, 20 Aug 2007 12:31:05 -0700

I have two questions for the forum.

I wrote the code below, and what I am trying to do is:

1) Firstly, and most importantly I have many products in my datasets and what to figure out what percent of my clients were lapsed (I am trying to automate the process, so the query can be run for multiple products at once). I have only prod = 'A' here listed in my sample code (but real data has A to infinity). How could I write this program such that it could compute the frequencies in the last line for multiple products (Say prod A to E) in one run? My data has tons of different products and I don’t want to be using the where statement to filter product after product? 2) Combine it into 1. Step 1 and 2 together in one program? Why because I think it’s good to write efficient programs. I like to shorten things;

You help in this matter would be greatly appreciated. Sample code below.

data have;

input id prod $ supply date mmddyy10. flg; format date date9.; datalines; 1 A 15 3/15/1990 0 1 A 30 4/26/1990 0 1 A 30 5/27/1990 1 1 A 60 7/18/1990 0 2 A 30 3/19/1997 0 2 A 30 3/20/1997 0 2 A 30 4/21/1997 1 2 A 30 5/22/1997 0 3 A 30 7/23/1983 0 3 A 30 9/24/1983 0 3 A 60 9/30/1983 1 3 A 60 12/6/1983 0 3 A 30 2/27/1984 0 4 A 90 1/28/1990 0 4 A 90 2/28/1990 0 5 A 90 8/29/2005 0 5 A 90 9/29/2005 0 6 A 90 7/30/2006 0 6 A 90 9/30/2006 0 7 A 30 9/28/1990 0 7 A 60 11/2/1990 1 8 A 45 1/2/1991 0 9 A 15 1/3/1991 1 9 A 15 3/3/1991 1 ;;; run; proc print data=have; run;

* Step 1 - days late computation ; data d_late ; set have; by id; format k prior_dt date7.; k=date +0; prior_dt=lag(date); prior_ds=lag(supply); if not first.id then do; Time_to_next=date-prior_dt; end; late=Time_to_next-prior_ds; Run; proc print data=d_late; run;

* Step 2 ~ figure out what percent of product A are lapsed (more than 15 days late); data d_late1 (keep = id avg_late Num sum_days lapsed); set d_late; by id; retain avg_late sum_days num lapsed; if first.id then do; sum_days = 0; Num = 0; avg_late = 0; lapsed = 0; end;

if late = . then late = 0; Num + 1; sum_days=sum_days+late; avg_late = sum_days/(Num-1); if avg_late gt 15 then lapsed = 1; if last.id then output; run; proc print; run; proc freq data = d_late1; tables lapsed; run;

--------------------------------- Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.

_________________________________________________________________ Booking a flight? Know when to buy with airfare predictions on MSN Travel. http://travel.msn.com/Articles/aboutfarecast.aspx&ocid=T001MSN25A07001


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