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 1997, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 14 May 1997 16:30:05 +0000
Reply-To:     "Aaron Dukes, qq" <adukes@ATTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         "Aaron Dukes, qq" <adukes@ATTMAIL.COM>
Subject:      Re: Retaining a character variable and concatenation
Comments: To: hu.ang@RHIGROUP.COM
Content-Type: Text/Plain; charset=us-ascii

What is happening is that the new values for hosp occupy positions 201-203 in the temporarily constructed string. When this is assigned back to a string of (maximum) length 200, these positions are dropped, soyou get what you had before.

Change

else hosplist = hosplist || hosp;

to

else hosplist = trim(hosplist) || hosp;

and you should get what you expected.

HTH, ====================================== Aaron L. Dukes, Consultant Statistician & SAS Developer

Breakthru Systems Development, Inc.

adukes@pdd.att.com bsd@idt.net

(201)895-2365 (201)443-2836 ======================================

---------- From: Hu Ang Sent: Wednesday, May 14, 1997 11:34 AM To: Multiple recipients of list SAS-L Subject: Retaining a character variable and concatenation

Hi SAS users,

I am trying to concatenate the character strings in each observation of a data set (please see the following code). With a numeric varaible cnt I get 3 at the end. The string varaible hosplist keeps the value 'abc' all the way to the end while I expected to see 'abcopqxyz'. Any thoughts? TIA

code: ____________________________ data temp; infile cards; input hosp $3.; cards; abc opq xyz ; run;

data _null_; retain hosplist; retain cnt;

length hosplist $200;

set temp; if _n_ = 1 then hosplist = hosp; else hosplist = hosplist || hosp;

if _n_ = 1 then cnt = 1; else cnt + 1;

put _all_; run; ______________________________

LOG: _____________________________ 1 data temp; 2 infile cards; 3 input hosp $3.; 4 cards;

NOTE: The data set WORK.TEMP has 3 observations and 1 variables. NOTE: The DATA statement used 1.24 seconds.

8 ; 9 run; 10 11 data _null_; 12 retain hosplist; 13 retain cnt; 14 15 length hosplist $200; 16 17 set temp; 18 if _n_ = 1 then hosplist = hosp; 19 else hosplist = hosplist || hosp; 20 21 if _n_ = 1 then cnt = 1; 22 else cnt + 1; 23 24 put _all_; 25 run;

HOSPLIST=abc CNT=1 HOSP=abc _ERROR_=0 _N_=1 HOSPLIST=abc CNT=2 HOSP=opq _ERROR_=0 _N_=2 HOSPLIST=abc CNT=3 HOSP=xyz _ERROR_=0 _N_=3 NOTE: The DATA statement used 0.24 seconds. _____________________________ Sincerely, Hu Ang


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