BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Barkamih
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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;
Barkamih
Pyrite | Level 9

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 

 

 

Barkamih
Pyrite | Level 9

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 

Kurt_Bremser
Super User

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.

gamotte
Rhodochrosite | Level 12

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 10853 views
  • 2 likes
  • 3 in conversation