Date: Sun, 23 Nov 2008 19:45:26 -0500
Reply-To: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject: Re: Column manipulation
In-Reply-To: <200811232332.mANBkrkA005576@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
On Sun, Nov 23, 2008 at 6:32 PM, Sid N <nsid31@gmail.com> wrote:
> I am new to array manipulation in SAS. I have a dataset with > 100 numeric
> variables with the same prefix "Pre." I am trying to add a separator before
> the last digit of each of the variable values in these columns.
>
> For example, I would like to change the values from the following columns
> below
>
> Pre1 Pre2 Pre3 ... Pre(n)
> 10231 10982 98191 23111
> 10451 21342 21452 13431
> . . . .
> . . . .
> . . . .
> 12931 12412 15642 19001
>
> to...
>
> Post1 Post2 Post3 ... Post(n)
> 1023-1 1098-2 9819-1 2311-1
> 1045-1 2134-2 2145-2 1343-1
> . . . .
> . . . .
> . . . .
> 1293-1 1241-2 1564-2 1900-1
>
> Can someone please help me with this? Thank you in advance.
>
> Sid
>
Yet another way. No need to have hard-coded dimension.
data have;
input pre1 pre2 pre3 pre4;
cards;
10231 10982 98191 23111
10451 21342 21452 13431
12931 12412 15642 19001
;
run;
data _null_;
if 0 then do;
set have nobs = nobs;
array _n[*] _numeric_;
end;
call symputx('nobs',nobs);
call symputx('nvars',dim(_n));
stop;
run;
%put &nobs;
%put &nvars;
data need;
set have;
array pre[*] pre:;
array post[&nvars] $ post1 - post&nvars;
do i = 1 to &nvars;
left = int(pre[i] / 10);
unit = pre[i] - left * 10;
post[i] = catx('-',left,unit);
end;
drop pre: i left unit;
run;
proc print data = need;
run;
Muthia Kachirayan