| Date: | Thu, 31 Jan 2008 07:59:38 -0800 |
| Reply-To: | "Terjeson, Mark" <Mterjeson@RUSSELL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Terjeson, Mark" <Mterjeson@RUSSELL.COM> |
| Subject: | Re: Appending new columns to every observation |
|
| In-Reply-To: | A<200801311532.m0VBuNAU006588@mailgw.cc.uga.edu> |
| Content-Type: | text/plain; charset="US-ASCII" |
Hi Ted,
A datastep or SQL can do this:
data sample;
var1 = 4;
var2 = 3.9;
var3 = 'hello';
var4 = 'there';
var5 = 0;
run;
* datastep ;
data result;
set sample;
if var1 - var2 > .05 then
new6 = var2 - var1;
else
new6 = 0;
run;
* SQL ;
proc sql;
create table result2 as
select
*,
case when var1 - var2 > .05 then
var2 - var1
else
0
end as new6
from
sample
;
quit;
Hope this is helpful.
Mark Terjeson
Senior Programmer Analyst, IM&R
Russell Investments
Russell Investments
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Ted
Sidehamer
Sent: Thursday, January 31, 2008 7:33 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Appending new columns to every observation
Greetings,
I have a SAS table that contains 5 million obervations. Each
observation
has 5 columns.
I'm trying to write sas code which uses a formula to append a new column
to every observation.
The formula needs to look at 2 columns in every observation something
like
this:
Psuedo Code:
If Row1.Column1.value - Row1.Column2.value > .05
then
Row1.New6thcolumn.Value = Row1.Column2.value - Row1.Column1.value
else
Row1.New6thcolumn.Value = 0
Any help would be greatly appreaciated.
|