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 (May 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 19 May 2004 16:00:54 -0400
Reply-To:     SAS Bigot <sas_bigot@ML1.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         SAS Bigot <sas_bigot@ML1.NET>
Subject:      Re: Adding a single value to each observation of a dataset
In-Reply-To:  <D859A1A91D36184C8C28B77BF899C0860F6E028A@ladybird.tea.state.tx.us>
Content-Type: text/plain; charset="US-ASCII"

After data sets a and b are created using the sample code below, run the following code:

data ab; set b; do until ( eof ); set a end=eof; output; end; run;

----- Original message ----- From: "Dunn, Toby" <tdunn@TEA.STATE.TX.US> To: SAS-L@LISTSERV.UGA.EDU Date: Wed, 19 May 2004 09:41:39 -0500 Subject: Re: Adding a single value to each observation of a dataset

Mark,

Laurel's solution will work and do what you want, even though "B" only has one observation. That value (of newprice) will be carried on all observations of "A".

Example: data a; input count $2. price $4.; cards; 101.00 121.10 111.20 131.30 141.40 151.50 161.60 171.70 191.80 201.90 ; run;

data b; newprice = "4.00"; run;

data a2; set a; n = 1; run;

data b2; set b; n = 1; run;

data ab; merge a b; by n; run;

proc print data = ab; run;

output: Obs count price newprice

1 10 1.00 4.00 2 12 1.10 4.00 3 11 1.20 4.00 4 13 1.30 4.00 5 14 1.40 4.00 6 15 1.50 4.00 7 16 1.60 4.00 8 17 1.70 4.00 9 19 1.80 4.00 10 20 1.90 4.00

Toby Dunn -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mark Biek Sent: Wednesday, May 19, 2004 9:37 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Adding a single value to each observation of a dataset

Laurel- The problem I run into with a merge is that the variable from B is only added to the first observation of A.

Mark

Copeland, Laurel wrote:

> Mark, > One simplistic approach (count on me for those) is to add a var in common > for the purpose of the merge: > > DATA a; > input count price; > cards; > 2 50 > 1 50 > 5 50 > 2 50 > 2 50 > 8 75 > 9 75 > 4 75 > 7 100 > 1 100 > ; > run; > DATA b; > input newprice; > cards; > 125 > ; > run; > data a; set a; > n=1; > run; > data b; set b; > n=1; > run; > DATA c(DROP=n); > MERGE a b; BY n; > RUN; > proc print data=c; run; > > Hth, laurel > > -----Original Message----- > From: Mark Biek [mailto:markb@STEVENSONCOMPANY.COM] > Sent: Wednesday, May 19, 2004 10:25 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Adding a single value to each observation of a dataset > > Let's say I have dataset A which has 2 variables, count & price and has 10 > observations. I also have dataset B which has 1 variable, newprice, and 1 > observation. > > I'd like to add the variable newprice from B to each observation of A. > > I couldn't figure it out using a merge or an update. What's the best way to > go about this? > > Mark > > -- > Mark Biek > The Stevenson Company > 8700 Westport Rd. Ste. 200 > Louisville, KY 40242-3100 > (502) 429-9060 ext 251 >

-- Mark Biek The Stevenson Company 8700 Westport Rd. Ste. 200 Louisville, KY 40242-3100 (502) 429-9060 ext 251

-- http://www.fastmail.fm - Same, same, but different…


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