LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (March 2010, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 30 Mar 2010 14:40:24 -0400
Reply-To:   Ya Huang <ya.huang@AMYLIN.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Ya Huang <ya.huang@AMYLIN.COM>
Subject:   Re: SQL and array
Comments:   To: V V B <vibooks@COMCAST.NET>

No need of array:

proc sql; select distinct id, case when max(status)='D' and min(status)='D' then 1 else 0 end as count, case when max(status)='D' and min(status)='D' then 'D' else 'P' end as tag from one group by id order by id ;

id count tag ----------------------- 057800 0 P 505360 1 D 505361 0 P

On Tue, 30 Mar 2010 14:03:14 -0400, V V B <vibooks@COMCAST.NET> wrote:

>Hi All, > >I have a dataset with 3 fields: Id line_num and status. > >I need to read each line of an id and create a new dataset with three >fields id, tag and count, based on the value found in status. > >Beginning values: >Tag='P'; >Count=0; > >If status = D for every line for same id then tag='D' and count=1. > >I think I need sql code to collect max count and then an array to create >new fields. However, I don't know how to do it. > >My goal is to count the number of unique id's with a status of D. > >Sample data and expected output below. > >Your help is most appreciated! > >Thanks! > >Vivian > >data one; >input id line_num status; > >cards; >505360 1 D >505360 2 D >505360 3 D >505360 4 D >057800 1 D >057800 2 A >057800 3 A >057800 4 A >057800 5 P >057800 6 D >057800 7 D >057800 8 D >057800 9 D >057800 10 D >057800 11 D >057800 12 D >057800 13 D >057800 14 D >057800 15 D >057800 16 D >505361 1 D >505361 2 C >505361 3 C >505361 4 D > >; >run; > >data two; >input id tag ct; > >cards; > >505360 D 1 >057800 P 0 >505361 P 0 >Run;


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