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 (July 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 28 Jul 2003 16:05:08 -0400
Reply-To:   Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:   Re: merge data
Comments:   To: "Chen, Jian" <ozz6@CDC.GOV>
Content-Type:   text/plain

Jian,

While the code works, it might be considered more complex than needed and deserves an explanation. Change the 3rd line to

if first.id then do ; put _n_= ; descr=""; end ;

to see what is happening.

You will find that the DO-block is executed at _N_ = 1 (doesn't matter), _N_ = 2 (fixes problem), and _N_ = 4 (fixes problem). In general the IF test will be true on the first record (because FIRST.ID is initialized to 1 when ID is included in a BY statement), on the first record following any BY-group of one record (because automatic variables are retained), and on the second record of any BY-group containing at least two records. Thus the blanking will be done where needed and sometimes when it doesn't matter.

IanWhitlock@westat.com -----Original Message----- From: Chen, Jian [mailto:ozz6@CDC.GOV] Sent: Monday, July 28, 2003 3:33 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: merge data

Code below also works:

Data step1; length descr $ 40; if first.id then descr=""; Merge set1(in=a) set2(in=b); By id; If a and b ; run ;

-----Original Message----- From: Mai To [mailto:Mai.To@UTH.TMC.EDU] Sent: Monday, July 28, 2003 1:50 PM To: Subject: merge data

I have two datasets:

Set1: ID DESCR 001 Cost of moving PCs from etc... 002 Move the switch boxes

Set2: ID LINE AMT 001 01 50.00 001 02 (50.00) 002 01 (100.00) 002 02 80.00 002 03 20.00

What I would like to have is

001 01 50.00 Cost of moving PCs from etc... 001 02 (50.00)

002 01 (100.00) Move the switch boxes 002 02 80.00 002 03 20.00

I used this stmt for merge:

Data step1; Merge set1(in=a) set2(in=b); By id; If a and b:

Proc sort data=step1; By ID;

And this is the result:

ID LINE AMT DESCR 001 01 50.00 Cost of moving PCs from etc... 001 02 (50.00) Cost of moving PCs from etc...

002 01 (100.00) Move the switch boxes 002 02 80.00 Move the switch boxes 002 03 20.00 Move the switch boxes

What can I do to have the DESCR just print on the first line?

Thanks.

Mia


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