Sunday 15 February 2015

SAS - Creating combinations of different independant variables with lags -


I would like to create dynamic entries in a data set (SAS) that are created using the names of variables (such as VarA, VarB, VarC) is above 4 in each.

The input data set contains this information (column name variables and values):

  variable value VarA 0 VarB 0 VarC 0 Lags 4   

and want the output data set to be something like the following (Var1, Var2, and Var3 are dynamic column names such as adding 1,2,3 to any string wise)

 < Code> var1 var2 var3 variant varb varc vara1 varb1 varc1 .. varA4 varB4 varC4   

The intention is that any number of variables for this data set is done.

Thanks

The following code returns what you want. Please modify according to your requirements.

  / * sample input dataset * / data is; Input variable $ value; Datalines; VarA 0 VarB 0 VarC 0 Long 4; Run; / * Get the number of skull input dataset * / proc sql noprint; Select values: num_of_lags where upcase (variables) is = 'LAGS'; leave; / * Transferring input datasets such as VarA, VarB, VarC to column Var1, Var2, and amp; Wind 3 respectively * / / * is the only line in the hatat, transgadadet dataset. * / Proc transpose data = out = UT_T (drop = _name_) prefix = hero; Where ups (variables) have 'LAGS'; Var variables; Run; / * Copies 1 row _ num_of_lags times * / data pre_want; Set_t; Array myVars {*} _character_; Do j = 1 & amp; Num_of_lags + 1; Do I = 1d (myVars); MyVars [i] = myVars [i]; End; Output; End; Run; / * Wants the last dataset * / data; Set pre_want; Array myVars {*} _character_; If _N_ & gt; 1 Do it again; Do I = 1d (myVars); MyVars [i] = Compressed (myVars [i] !! _ n_ -1); End; End; Drop IJ; Run; Proc print data = want; Run;   

Output:

  var1 var2 var3 VarA VarB VarC VarA1 VarB1 VarC1 VarA2 VarB2 VarC2 VarA3 VarB3 VarC3 VarA4 VarB4 VarC4   < / Div> 

No comments:

Post a Comment