dear all:
I know how to do one-hot encoding with data step.Is it possible to do it by using proc transpose?
data basic_info;
input name $ sex $;
datalines;
A Female
B Male
C Female
D Female
E Male
;
run;
Any sugesstion is welcome!
You need to have a value which you can transpose.
data basic_info;
input name $ sex $;
val = 1;
datalines;
A Female
B Male
C Female
D Female
E Male
;
proc transpose data=basic_info out=want1 (drop=_name_);
by name;
var val;
id sex;
run;
data want;
merge
basic_info
want1
;
by name;
run;
Conversion of missing to 0 can be done manually in the MERGE step, or with PROC STDIZE.
data basic_info;
input name $ sex $;
dummy=1;
datalines;
A Female
B Male
C Female
D Female
E Male
;
run;
proc glmselect data=basic_info outdesign(addinputvars)=want(drop=dummy);
class sex;
model dummy=sex/selection=none noint;
run;
You need to have a value which you can transpose.
data basic_info;
input name $ sex $;
val = 1;
datalines;
A Female
B Male
C Female
D Female
E Male
;
proc transpose data=basic_info out=want1 (drop=_name_);
by name;
var val;
id sex;
run;
data want;
merge
basic_info
want1
;
by name;
run;
Conversion of missing to 0 can be done manually in the MERGE step, or with PROC STDIZE.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.