Date: Thu, 17 Oct 2002 17:06:27 -0400
Reply-To: "Dorfman, Paul" <Paul.Dorfman@BCBSFL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dorfman, Paul" <Paul.Dorfman@BCBSFL.COM>
Subject: Re: Flag
Content-Type: text/plain; charset=iso-8859-1
Ed,
Let me please submit my maladroit attempt at one-step SQL (undoubtedly
inspired by watching Sig and Ya bend SQL to their wills):
%let c = calculated ;
proc sql ;
create table flag (drop = _:) as
select id, x, sum(x) as _x, sum(abs(x)) as _a,
case when &c _x < &c _a then -2 else 2 end as flag
from test group by id
;
quit ;
Kind regards,
---------------------
Paul M. Dorfman
Jacksonville, FL
---------------------
> -----Original Message-----
> From: Ed Heaton [mailto:EdHeaton@WESTAT.COM]
> Sent: Thursday, October 17, 2002 3:40 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Flag
>
>
> Asheber;
>
> Given the data set created below.
> Data test ;
> Infile cards ;
> Input id x1 ;
> Cards4 ;
> 12 2
> 12 3
> 12 -1
> 13 5
> 13 6
> 13 6
> 14 4
> 14 -3
> 14 3
> ;;;;
>
> You can use this two-step process.
> Proc sql ;
> Create table flags as
> select id , min(x1) as min
> from test
> group by id
> ;
> Quit ;
> Data FlaggedTest(drop=min) ;
> Merge test flags ;
> By id ;
> If ( min < 0 )
> then flag = -2 ;
> Else flag = 2 ;
> Run ;
>
> Ed
>
> Edward Heaton, Senior Systems Analyst,
> Westat (An Employee-Owned Research Corporation),
> 1550 Research Boulevard, Room 2018, Rockville, MD 20850-3195
> Voice: (301) 610-4818 Fax: (301) 294-3992
> mailto:EdHeaton@westat.com http://www.westat.com
>
> -----Original Message-----
> From: Asheber Sewalem [mailto:sewalem@CDN.CA]
> Sent: Thursday, October 17, 2002 2:46 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Flag
>
>
> Hi all,
>
> A simple question!
> I have two variables id and x1. I just want to flag all "Id"
> records -2
> if any of the records x1 within id is less than 0 otherwise flag=2.
>
> A sample data,
>
> id x1
> 12 2
> 12 3
> 12 -1
> 13 5
> 13 6
> 13 6
> 14 4
> 14 -3
> 14 3
>
>
> The desired output should be the following,
>
> id x1 flag
> 12 2 -2
> 12 3 -2
> 12 -1 -2
> 13 5 2
> 13 6 2
> 13 6 2
> 14 4 -2
> 14 -3 -2
> 14 3 -2
>
> Asheber
>
Blue Cross Blue Shield of Florida, Inc., and its subsidiary and
affiliate companies are not responsible for errors or omissions in this e-mail message. Any personal comments made in this e-mail do not reflect the views of Blue Cross Blue Shield of Florida, Inc.
|