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 (July 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 16 Jul 2010 21:47:59 -0400
Reply-To:     SUBSCRIBE SAS-L Anonymous <hari.sas.j@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         SUBSCRIBE SAS-L Anonymous <hari.sas.j@GMAIL.COM>
Subject:      Counter

Hi, I have a dataset with three variables, subject date flag. Basically I need to index in such a away that as soon as the flag = 1 then index is set 0 and any observation which has a lower value date is indexed -1, -2 and so on .. and any observation that has higher date value than the (flag = 1) is indexed +1, +2 and so on within the group subject.Below is the program that creates raw data and also the desired output is shown below as well

data alldata;

input subject $ date $12. flag; datalines; Subject1 5/1/2010 0 Subject1 6/1/2010 0 Subject1 7/1/2010 1 Subject1 8/1/2010 0 Subject1 9/1/2010 0 Subject1 10/1/2010 0 Subject2 1/1/2010 0 Subject2 2/1/2010 1 Subject2 3/1/2010 0 Subject2 4/1/2010 0 ; run;

data alldata1; set alldata (rename = (date = datem));

date = input(datem,mmddyy10.);

format date date9.; run;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Desired output:

subject date flag index Subject1 5/1/2010 0 -2 Subject1 6/1/2010 0 -1 Subject1 7/1/2010 1 0 Subject1 8/1/2010 0 1 Subject1 9/1/2010 0 2 Subject1 10/1/2010 0 3 Subject2 1/1/2010 0 -1 Subject2 2/1/2010 1 0 Subject2 3/1/2010 0 1 Subject2 4/1/2010 0 2

Advanced thanks for help

Regards,

Hari


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