d**********0 发帖数: 222 | 1 拿到一组SAS DATASET,有100多个COLUMNS,但不是对每个COLUMN一一分析。有部分
COLUMN里面的值是“YES”或“NO”。现在就想对这些COLUMN进行分析,请问怎么获取
这些COLUMN的NAMES。 | d******9 发帖数: 404 | 2 Below code may be not a perfect method, but it works.
Use the SASHELP Class data set to create a sample data set.
data A;
retain X Name Y Sex Z Age Height Weight;
set sashelp.class;
if ranuni(7546)<0.3 then X='Yes';
else if ranuni(7546)<0.5 then X='No';
else X=' ';
if ranuni(32681)<0.4 then Y='Yes';
else if ranuni(32681)<0.8 then Y='No';
else Y='***';
if ranuni(510)<0.6 then Z='Yes';
else if ranuni(33201)<0.8 then Z='No';
else Z='N/A';
run;
*******************************
Use array, find all the _Char_ columns and put them into the array. Say, in
this case, we have 5 CHAR vars.
data B;
length Combination $100;
set A;
array VB(*) $10 Name Sex X Y Z;
array VC(*) $10 T1-T5;
do I=1 to 5;
if VB(I) in ('Yes', 'No') then VC(I)=Vname(VB(I));
end;
Combination=catX(",", of T1-T5);
L=Length(Combination);
run;
******************** Create a macro variable to hold all the required
columns. **********;
proc sql;
select strip(Combination) into : Comb
from B
having max(L);
quit;
%put Comb= *&Comb*;
SAS Output:
Comb= *X,Y,Z *;
| d**********0 发帖数: 222 | 3 特别感谢dido2009 这样热心的牛人。可否拜师? | d******9 发帖数: 404 | 4 不敢当。Take care.
【在 d**********0 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 特别感谢dido2009 这样热心的牛人。可否拜师?
|
|