Date: Wed, 5 Mar 2003 12:17:32 -0500
Reply-To: "Cacialli, Doug" <Doug_Cacialli@URMC.ROCHESTER.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Cacialli, Doug" <Doug_Cacialli@URMC.ROCHESTER.EDU>
Subject: Re: Concatenation issue
Content-Type: text/plain
Greg Woolridge wrote me and suggested something very similar. I tried
running something very similar yesterday and couldn't get it to work, and
for the life of me didn't understand the error messages coming back in the
log. I subsequently abandoned the idea of using an array.
I just ran it again to produce the error message so that I could post it,
when I realized that it wasn't working because I'd misspelled 'TEXT'. I
fixed the spelling error, and it works perfectly.
And so it goes, decent programming is once again thwarted by my inability to
spell simple four-letter words. Thank you all for your assistance.
Doug out.
-----Original Message-----
From: Droogendyk, Harry [mailto:Harry.Droogendyk@CIBC.COM]
Sent: Wednesday, March 05, 2003 11:58 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Concatenation issue
You could do this without macro by creating an array of your diagnosis_text
variables. Either way, the important piece you're missing is the TRIM on
the right side of the equal sign. SAS right pads character variables with
spaces if the value is shorter than the field length. Without the trim the
next diagnosis_text is appended to the end of lifetime_diagnosis, that is,
past the actual length of the field, hence the addition is truncated.
length lifetime_diagnosis $1000;
array diagnosis_text{*} diagnosis_text: ;
lifetime_diagnosis = '' ;
do j = 1 to dim(diagnosis_text); /* or use the value from &MAX_AFFECTIVE
*/
lifetime_diagnosis = trim(lifetime_diagnosis) || diagnosis_text(j);
end;
-----Original Message-----
From: Cacialli, Doug
[mailto:Doug_Cacialli@URMC.ROCHESTER.EDU]
Sent: March 5, 2003 11:48 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Concatenation issue
Y'all,
I'm working with 14 years of longitudinal data, where each
year subjects are
assessed for diagnosable mental illness (this is a gross
oversimplification
of what we do). In the event of new mental illness (i.e., a
diagnosis not
previously made for a given subject), the diagnosis is
entered as
DIAGNOSIS_TEXTi, where 'i' is a numeric suffix. For
example:
If an individual was diagnosed with Major depression,
Alcohol dependence,
and Panic disorder in this sequence, then DIAGNOSIS_TEXT1 =
'Major
depression', DIAGNOSIS_TEXT2 = 'Alcohol dependence', and
DIAGNOSIS_TEXT3 =
'Panic disorder'. If three years from now this subject was
diagnosed with
Schizophrenia, then DIAGNOSIS_TEXT4 would be created, and
DIAGNOSIS_TEXT4 =
Schizophrenia.
I have been tasked with creating a variable called
LIFETIME_DIAGNOSIS, which
will be the concatenation of an unknown number of
DIAGNOSIS_TEXTi variables
(this is unknown because diagnoses are being added
constantly, I'm quitting
this awful job two months from now, and I'd like the program
to continue
working after I leave). I'd thought about doing this with a
macro:
%MACRO MODULE0033_MACRO4;
%DO i = 1 %TO &MAX_AFFECTIVE;
%IF i = 1 %THEN %DO;
LIFETIME_DIAGNOSIS =
TRIM(LEFT(DIAGNOSIS_TEXT&i));
%END;
%ELSE %IF i > 1 %THEN %DO;
LIFETIME_DIAGNOSIS = LIFETIME_DIAGNOSIS ||
TRIM(LEFT(DIAGNOSIS_TEXT&i));
%END;
%END;
%MEND MODULE0033_MACRO4;
But LIFETIME_DIAGNOSIS COMES BACK "". Does anyone have any
ideas how I can
get the macro to work, or possibly suggest another route to
concatenation?
I think Excel has something like
"CONCATENATE(DIAGNOSIS_TEXT1,DIAGNOSIS_TEXT2,etc.)"; is
there something
similar in SAS that I don't know about? Any assistance
would be great.
Thanks!
Doug out.
---------------------------------------------------
Douglas Cacialli - Data Manager / Data Analyst
Sleep and Depression Research Laboratory
University of Rochester Medical Center
300 Crittenden Blvd. - Box PSYCH
Rochester, New York 14642
Phone: (585)273-3309 Fax: (585)506-0287
---------------------------------------------------