|
On May 16, 1:56 pm, muthia.kachira...@GMAIL.COM (Muthia Kachirayan)
wrote:
> On Fri, May 16, 2008 at 11:50 AM, shankera <shanker_an...@hotmail.com>
> wrote:
>
> > I have a dataset with 100s of variables, and I want to add ones with
> > the suffix "_pending". Is there a way to do it without having to
> > write out 30 some variable names?
>
> Using the vname function of the variable and whether it has
> underscore-character in the name, the summation can be done for all
> _numeric_ variables in the data set. Instead of underscore, the word,
> pending, can be looked as an alternative.
>
> data new;
> input f_pending g_pending l_pending h_pending control;
> cards;
> 5 56 5 2 7
> 6 2 5 6 52
> 5 5 4 5 78
> 6 5 2 8 9
> 7 5 2 1 7
> ;
> run;
> data need;
> length name $32;
> set new;
> array nv _numeric_;
> do over nv;
> name = vname(nv[_i_]);
> if indexc(name,'_') then sum = sum(sum, nv[_i_]);
> * if index(name,'pending') then sum = sum(sum, nv[_i_]);
> end;
> run;
> proc print data = need;
> run;
>
> Muthia Kachirayan
Thanks! I figured out using similar code.
|