Prev: Who can give me some advices SASHELP View and Dictionary
Next: Is it possible to empty the SAS log file without ending the
From: laika on 29 Jan 2010 06:03 Hi, Ik have a large SAS-dataset with a lot of variables. I have to multiplay each variable with -1. Is there a short way to do this by using a macro? Now i have to do : X1 = X1 * -1 ; X2 = X2 * -1 ; .. .. X100 = X100 * -1 ; Tx
From: TheSharpOne on 29 Jan 2010 06:09 it won't be pretty but you could try something likethe code below. Just replace WORK with your library name and SAMPLE with your table name: Proc SQL NoPrint; Select Trim(Name)!!' = '!!Trim(Name)!!'*-1;' INTO : varlist separated by ' ' From Dictionary.columns Where libname = 'WORK' AND memname = 'SAMPLE' ; Quit; Data x1; set x; &varlist; Run;
From: Alex on 29 Jan 2010 06:42 On Jan 29, 12:10 pm, laika <michel.verhe...(a)axa.be> wrote: > Hi, > > Ik have a large SAS-dataset with a lot of variables. > I have to multiplay each variable with -1. Is there a short way to do > this by using a macro? Now i have to do : > X1 = X1 * -1 ; > X2 = X2 * -1 ; > . > . > X100 = X100 * -1 ; > > Tx Hi Laika, If you really want to multiply all numeric variables you can use an array with the keyword _numeric_ (or even _all_ if you don't have any character variables): data want (drop = i); set have ; array all_num (*) _numeric_ ; do i = 1 to dim(all_num) ; all_num(i) = all_num(*) * -1 ; end; run; Best, Alex
From: data _null_; on 29 Jan 2010 08:11 On Jan 29, 5:03 am, laika <michel.verhe...(a)axa.be> wrote: > Hi, > > Ik have a large SAS-dataset with a lot of variables. > I have to multiplay each variable with -1. Is there a short way to do > this by using a macro? Now i have to do : > X1 = X1 * -1 ; > X2 = X2 * -1 ; > . > . > X100 = X100 * -1 ; > > Tx An alternative that allows us to learn a little more SAS would be to build a custom scoring data set for use with PROC SCORE. This is a trivial application but sometimes trivial is good for learning. We also get to use PROC TRANPOSE with the little know and mostly unused COPY statement. %let data=sashelp.class; proc transpose data=&data(obs=1) out=numXPO(drop=col1); var _numeric_; copy _numeric_; run; data score; retain _type_ 'SCORE'; length _name_ $32; set numXPO end=eof; array _v[*] _numeric_; call missing(of _v[*]); * times minus 1; do _n_ = 1 to dim(_v); if vname(_v[_n_]) eq _name_ then _v[_n_] = -1; end; _name_ = cats(_name_,'_M1'); output; * pairwise differences; if eof then do; do i = 1 to dim(_v); do j = i+1 to dim(_v); call missing(of _v[*]); _v[i]=1; _v[j]=-1; _name_ = catx('_M_',vname(_v[i]),vname(_v[j])); output; end; end; end; drop i j; run; proc print; run; proc score data=&data score=score out=Scored; run; proc print data=Scored(obs=19); run;
From: Mark D H Miller on 30 Jan 2010 16:20
Is not x * -1 the same as x = -(x) !!! .... Mark Miller On 1/29/2010 6:09 AM, TheSharpOne wrote: > it won't be pretty but you could try something likethe code below. > Just replace WORK with your library name and SAMPLE with your table > name: > Proc SQL NoPrint; > Select Trim(Name)!!' = '!!Trim(Name)!!'*-1;' INTO : varlist > separated by ' ' > From Dictionary.columns > Where libname = 'WORK' AND memname = 'SAMPLE' > ; > Quit; > > Data x1; > set x; > &varlist; > Run; > > |