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 (September 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 24 Sep 2007 17:16:00 +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: Create variables based on location codes that contains number
              of days in that location
Comments: To: harmonl@WSIPP.WA.GOV
In-Reply-To:  <DB76FB88D103F443B3AB818037EB273BBDC61E@ginger.wsipp.wa.gov>
Content-Type: text/plain; format=flowed

Laura ,

Use a Data Step to select correct obs and create number of days :

Data Temp ; Set Have ; Where LocCode In ( '704' '711' '719' '725' '726' '727' '728' '729' ) ;

NumOfDays = <You Logic Here> ;

Run ;

Then Use Proc Summary to Add your Days Per Person Together:

Proc Summary Data = Temp NWay ; Class LocCode DocPrisonStayID ; Output Out = SummedDays Sum( NumOfDays ) As NumOfDays ; Run ;

Then If You need a report use Proc Tabulate or Report to spit the report out, or if you need a denormalized data set to send to someone just transpose the data.

Toby Dunn

Compromise is like telling a lie, it gets easier and easier. Each comprimise you make, that becomes your standard.

Perfection doesnt exist, once you reach it, its not perfect anymore. It means something else.

From: "Harmon, Laura" <harmonl@WSIPP.WA.GOV> Reply-To: "Harmon, Laura" <harmonl@WSIPP.WA.GOV> To: SAS-L@LISTSERV.UGA.EDU Subject: Create variables based on location codes that contains number of days in that location Date: Mon, 24 Sep 2007 10:04:47 -0700

Hi all,

I can't think how to do this and am crunched for time. The following is some code that works but I don't like creating the WrCodes array to do this, I think there is a way with macro variables or maybe using _Temporary_ arrays somehow to put the locations codes into memory and do a look-up?

What I want to do is create a set of variables based on selected values of LocCode, for this example the list of values of interest would be '704', '711', '719', '725', '726', '727', '728' and '729'. I want to create 8 new variables that would contains the number of days in each of these locations for each DocPersonNumber DocPrisonStayID.

Any suggestions on a better method to do this?

data test;

format inLocDate OutLocDate mmddyy10.;

DocPersonNumber=1;DocPrisonStayID=1;inLocDate=mdy(4,5,99);outLocDate=mdy (6,7,00);LocCode='704';output;

DocPersonNumber=2;DocPrisonStayID=2;inLocDate=mdy(1,1,00);outLocDate=mdy (1,14,00);LocCode='704';output;

DocPersonNumber=2;DocPrisonStayID=2;inLocDate=mdy(1,16,00);outLocDate=md y(1,20,00);LocCode='704';output;

DocPersonNumber=2;DocPrisonStayID=2;inLocDate=mdy(1,21,00);outLocDate=md y(1,26,00);LocCode='719';output;

DocPersonNumber=2;DocPrisonStayID=2;inLocDate=mdy(1,28,00);outLocDate=md y(1,30,00);LocCode='719';output;

DocPersonNumber=2;DocPrisonStayID=2;inLocDate=mdy(2,10,00);outLocDate=md y(2,20,00);LocCode='711';output;

DocPersonNumber=3;DocPrisonStayID=3;inLocDate=mdy(11,4,01);outLocDate=md y(12,11,02);LocCode='H06';output;

run;

proc sort data=test;

by DocPersonNumber DocPrisonStayID inLocDate outLocDate;

run;

data test2(keep=DocPersonNumber DocPrisonStayID WR704 WR711 WR719 WR725 WR726 WR727 WR728 WR729);

set test;

by DocPersonNumber DocPrisonStayID;

retain WR704 WR711 WR719 WR725 WR726 WR727 WR728 WR729 ;

length WR704 WR711 WR719 WR725 WR726 WR727 WR728 WR729 3;

array WRDays(8) WR704 WR711 WR719 WR725 WR726 WR727 WR728 WR729;

array WrCodes(8) $3 Code704 Code711 Code719 Code725 Code726 Code727 Code728 Code729;

do i=1 to 8;

if first.DocPrisonStayID then WRDays(i)=0;

end;

i=1;

do while(i le 7);

do c='704','711','719','725','726','727','728','729';

WrCodes(i)=c;

i=i+1;

end;

end;

do i=1 to 8;

if LocCode eq WrCodes(i) then WRDays(i)=WRDays(i)+(OutLocDate-InLocDate+1);

end;

if last.DocPrisonStayID then output;

run;

Thanks!

Laura Harmon

Washington State Institute for Public Policy

360 586-2766

harmonl@wsipp.wa.gov

www.wsipp.wa.gov <file:///C:\Documents%20and%20Settings\harmonl\Application%20Data\Micros oft\Signatures\www.wsipp.wa.gov>

_________________________________________________________________ Can you find the hidden words? Take a break and play Seekadoo! http://club.live.com/seekadoo.aspx?icid=seek_hotmailtextlink1


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