Hi all
I have made this code to transform all my variable's data into log form.
my question
is there any code to transform all data variables together in one single small code OR I need to do so individually as my this code does?
Regards
data LOG;
set have;
logA = log(A_1);
logB = log(B_1);
logC = log(C_1);
logD = log(D_1);
run; quit;
Retrieve the column names from sashelp.vcolumn, and use call execute:
data _null_;
set sashelp.vcolumn end=eof;
where libname = 'WORK' and memname = 'HAVE' and type = 'num';
if _n_ = 1 then call execute('data log; set have;');
call execute('log' !! trim(name) !! ' = log(' !! trim(name) !! ');');
if eof then call execute('run;');
run;
Retrieve the column names from sashelp.vcolumn, and use call execute:
data _null_;
set sashelp.vcolumn end=eof;
where libname = 'WORK' and memname = 'HAVE' and type = 'num';
if _n_ = 1 then call execute('data log; set have;');
call execute('log' !! trim(name) !! ' = log(' !! trim(name) !! ');');
if eof then call execute('run;');
run;
thanks for your response
I don't get it yet
What I should to change if my data name Is Have and these are my variable (Samples GROUP ACTB CCL2 FGF2 MMP1 NFKB2 PTGES PTGI)
I got this error
ERROR: Variable libname is not on file WORK.HAVE.
regards
Sorry was so busy,
I'm using your code and I did not change anything, I got confused about how to change it.
How the code should look like if my data has a name of HAVE.
Regards
My code works for a dataset named "HAVE" in the work library.
This line
where libname = 'WORK' and memname = 'HAVE' and type = 'num';
does all the selections. Library, dataset and variables. If you want to work on a specific set of variables that cannot be sufficiently determined jzst by type, use
and name in('NAME1','NAME2')
(just an example)
For further help, post an example of your data (in a data step with datalines, see my footnotes) and the code you tried.
Hello,
You can use arrays :
data have;
input A_1 B_1 C_1 D_1;
cards;
1 2 3 4
5 6 7 8
;
run;
proc sql noprint;
SELECT NAME, cats('Log',substr(NAME,1,1))
INTO :vars SEPARATED BY ' ', :logs SEPARATED BY ' '
FROM dictionary.columns
WHERE LIBNAME="WORK" AND MEMNAME="HAVE";
quit;
data want;
set have;
array A &vars.;
array B &logs.;
do over A;
B=log(A);
end;
run;
Edit : I didn't use the same variables names as in your question => added a request on dictionary columns to
generate the arrays definitions.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.