I am reading in variables from a few different datasets using proc sql, which I am trying to improve on.
What I'd like to do is read in a variable from a dataset using proc sql, but take the log of the variable as it's read in, but keep the variable name.
PROC SQL;
CREATE TABLE all AS
SELECT DISTINCT a.*,
b.var1, LOG(b.var2) AS log_var2
FROM pop AS a
INNER JOIN trt AS b
ON a.study=b.study AND a.subj=b.subj
;
QUIT;
The above creates a table with the variable log_var2, but it does not have the variable name from var2. Is there a way to keep this? The idea is that the label is used later on when transposing and the label is used as values within a table, but var2 itself may change so I need a robust method of labelling log_var2 with the label name from var2.
Any ideas?
Thanks in advance
As far as I know, there is not a way of persisting the variable label automatically in
proc sql
. Unfortunately, you don't have access to thevlabel
etc. functions, and even if you did the timing would be wrong to use them.In addition to defining the label manually as yukclam9 shows, you can obtain that value using variable information functions, or perhaps more easily in a data step beforehand. This would be handy if you don't want to hard-code the value in the program.
You could of course keep out the "Log of" part if you want just the original label, it's just included to show you could also add that.