Hi,
I often have to transform large sets of variables for use in regression, and how I normally hand the task is to manually code arrays for each of the new transformed variables, similar to the this example:
data example;
input A B C;
array var
array change
do i = 1 to dim(change);
change = var/lag(var) - 1;
end;
datalines;
10 20 30
15 5 60
25 30 10
run;
This becomes very tedious when you have large numbers of variables. I was hoping to get to something like the following, but I have not been able to create functioning code. Not sure if a macro loop is the right way to go, been trying to use a combination of vname and cat functions but no luck so far.
data example;
input A B C;
array var
array change
do i = 1 to dim(change);
change = var/lag(var) - 1;
end;
datalines;
10 20 30
15 5 60
25 30 10
run;
Any ideas?
is the example helpful?
proc sql noprint;
select name into : names separated by ' '
from dictionary.columns
where libname="SASHELP" and memname="CLASS" and type="num";
select cats('r_',name) into : r_names separated by ' '
from dictionary.columns
where libname="SASHELP" and memname="CLASS" and type="num";
quit;
data want;
set sashelp.class;
array var
is the example helpful?
proc sql noprint;
select name into : names separated by ' '
from dictionary.columns
where libname="SASHELP" and memname="CLASS" and type="num";
select cats('r_',name) into : r_names separated by ' '
from dictionary.columns
where libname="SASHELP" and memname="CLASS" and type="num";
quit;
data want;
set sashelp.class;
array var
I tried this code but I get the following error in my log:
2335 array var
-
22
200
WARNING: Apparent symbolic reference NAMES not resolved.
2336 array change
-
22
200
WARNING: Apparent symbolic reference R_NAMES not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, a numeric constant, $, (, ;,
_ALL_, _CHARACTER_, _CHAR_, _NUMERIC_, _TEMPORARY_.
ERROR 200-322: The symbol is not recognized and will be ignored.
I am using the code exactly, just with sashelp and class replaced with the library and data set that I am using. I am not familiar with proc sql, is this the correct implementation?
Thanks!
where libname="SASHELP" and memname="CLASS" and type="num";
The red parts have to be upcase.
That worked! Thank you!
Consider using new observations for the transformation. With an ID to sort them.
TRANSFORM
NONE
LOG
SQRT
I will consider using new observations but it will require me to rethink the way I do the regression and other procedures. Thank you!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.