[prev in list] [next in list] [prev in thread] [next in thread]
List: sas-l
Subject: SAS Forum: Transforming large number of variables
From: Roger DeAngelis <rogerjdeangelis () GMAIL ! COM>
Date: 2018-06-28 9:51:47
Message-ID: 2177261340458133.WA.rogerjdeangelisgmail.com () listserv ! uga ! edu
[Download RAW message or body]
SAS Forum: Transforming large number of variables
Two solutions
1. SQL datastep
2. DOSUBL (just datastep)
SQL dictionary queries can sometimes take 10-30 minutes on a large EG server
with many pre-defined librefs. Transpose, proc contents and arrays offer \
alternatives.
see
https://tinyurl.com/ybsmfx9u
https://communities.sas.com/t5/General-SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473878
PGStats
https://communities.sas.com/t5/user/viewprofilepage/user-id/462
OUTPUT
Added these variables
Up to 40 obs from class total obs=19 \
+++++++++++++++++++++++++++++++++++
LOG_ LOG_
Obs NAME SEX AGE HEIGHT WEIGHT LOG_AGE HEIGHT WEIGHT \
I
1 Alfred M 14 69.0 112.5 2.63906 4.23411 4.72295 \
4 2 Alice F 13 56.5 84.0 2.56495 4.03424 4.43082 \
4 3 Barbara F 13 65.3 98.0 2.56495 4.17899 4.58497 \
4
PROCESS
%macro logvars(dsn);
proc sql;
select cats("Log_",name) into :vlist separated by ' '
from dictionary.columns
where memname = upcase("&dsn") and TYPE="num";
quit;
data log_&dsn;
set &dsn;
array v _numeric_;
array lv &vlist;
do i = 1 to dim(v);
if v{i} > 0 then lv{i} = log(v{i});
end;
drop i;
run;
%mend;
data want;
length nams $4096;
set sashelp.class(obs=1);
array nums[*] _numeric_;
do i=1 to dim(nums);
nams=catx(" ",nams,cats('log_',vname(nums[i])));
end;
call symputx('nams',nams);
rc=dosubl('
data class;
set sashelp.class;
array nums[*] _numeric_;
array logs[*] &nams;
do i=1 to dim(nums);
logs[i]=log(nums[i]);
end;
drop i;
run;quit;
');
run;quit;
Added these
Up to 40 obs from class total obs=19 \
+++++++++++++++++++++++++++++++++++
LOG_ LOG_
Obs NAME SEX AGE HEIGHT WEIGHT LOG_AGE HEIGHT WEIGHT \
I
1 Alfred M 14 69.0 112.5 2.63906 4.23411 4.72295 \
4 2 Alice F 13 56.5 84.0 2.56495 4.03424 4.43082 \
4 3 Barbara F 13 65.3 98.0 2.56495 4.17899 4.58497 \
4 4 Carol F 14 62.8 102.5 2.63906 4.13996 4.62986 \
4 5 Henry M 14 63.5 102.5 2.63906 4.15104 4.62986 \
4 6 James M 12 57.3 83.0 2.48491 4.04830 4.41884 \
4 7 Jane F 12 59.8 84.5 2.48491 4.09101 4.43675 \
4 8 Janet F 15 62.5 112.5 2.70805 4.13517 4.72295 \
4 9 Jeffrey M 13 62.5 84.0 2.56495 4.13517 4.43082 \
4 10 John M 12 59.0 99.5 2.48491 4.07754 4.60016 \
4 11 Joyce F 11 51.3 50.5 2.39790 3.93769 3.92197 \
4 12 Judy F 14 64.3 90.0 2.63906 4.16356 4.49981 \
4 13 Louise F 12 56.3 77.0 2.48491 4.03069 4.34381 \
4 14 Mary F 15 66.5 112.0 2.70805 4.19720 4.71850 \
4 15 Philip M 16 72.0 150.0 2.77259 4.27667 5.01064 \
4 16 Robert M 12 64.8 128.0 2.48491 4.17131 4.85203 \
4 17 Ronald M 15 67.0 133.0 2.70805 4.20469 4.89035 \
4 18 Thomas M 11 57.5 85.0 2.39790 4.05178 4.44265 \
4 19 William M 15 66.5 112.0 2.70805 4.19720 4.71850 \
4
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic