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!
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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: