| Date: | Fri, 23 Jun 2006 08:17:03 -0700 |
| Reply-To: | chris@OVIEW.CO.UK |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | chris@OVIEW.CO.UK |
| Organization: | http://groups.google.com |
| Subject: | Re: Array questions (data set restructuring) |
|
| In-Reply-To: | <20060622164145.59450.qmail@web35107.mail.mud.yahoo.com> |
| Content-Type: | text/plain; charset="iso-8859-1" |
|---|
Hi Xamil,
The clue to your problem is that your final datastep never refers to
the value of 'prog'. Try this:
do j=b_mo to mo;
if prog='aa' then xx[j]=prog;
if prog='bb' then xx[j+3]=prog;
if prog='cc' then xx[j+6]=prog;
end;
Chris.
--------------------------------------------------------
Elvis SAS Log Analyser - http://www.oview.co.uk/elvis
--------------------------------------------------------
xamil kaisar wrote:
> Hello, SAS folks:
>
> I would appreciate if anyone can help with my program.
> The data set here is a miniature version of my
> data. This is what I want to do: transform the data
> set from many-obs-per-subj to one-obs-per-subj, with
> new variables representing the time span, and the
> values for these new variables are populated by PROG
> Here is my codes, but the output is not what I wanted.
> Thanks much in advance for your time !!!
>
>
> options nodate nonumber nocenter formdlim='-';
> data a;
> input ID @5 ServiceDate date9. Prog $ Cost;
> mo= intck( 'month', '01jan2001'd, ServiceDate )+1 ;
> drop ServiceDate;
> cards;
> 111 03feb2001 aa 123
> 111 06mar2001 bb 333
> 222 07mar2001 bb 432
> 222 09feb2001 cc 100
> 222 10mar2001 cc 283
> 333 14jan2001 aa 342
> 333 15feb2001 cc 332
> 333 12jan2001 cc 293
> 333 12mar2001 cc 332
> 333 10feb2001 aa 100
> 333 12mar2001 bb 324
> 444 03jan2001 aa 333
> 444 06feb2001 bb 341
> 444 07jan2001 bb 231
> 444 09jan2001 cc 233
> 444 10mar2001 cc 239
> ;
> proc print data=a;
> run;
> proc sort data=a out=a_sorted; by id mo;
> run;
> data b;
> retain id aa1-aa3 bb1-bb3 cc1-cc3 b_mo mo;
> array xx[*] $ aa1 - aa3 bb1 - bb3 cc1 - cc3 ;
> set a_sorted;
> by id mo;
> if first.id then
> do;
> b_mo=mo;
> do i=1 to dim(xx);
> xx[i]=' ';
> end;
> end;
> do j=b_mo to mo;
> xx[j]=prog;
> end;
> if last.id ;
> keep id aa1 -- cc3;
> run;
>
> proc print; run;
>
> *---------------------------------------------------;
> This is what (undesired result) I got from the codes:
> *---------------------------------------------------;
>
>
> The SAS System
>
> id aa1 aa2 aa3 bb1 bb2 bb3 cc1 cc2 cc3
> 111 bb bb
> 222 cc cc
> 333 bb bb bb
> 444 cc cc cc
>
> *--------------------;
> This is what I wanted:
> *--------------------;
> id aa1 aa2 aa3 bb1 bb2 bb3 cc1 cc2 cc3
> 111 aa bb
> 222 bb cc cc
> 333 aa aa bb cc cc cc
> 444 aa bb bb cc cc
>
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
|