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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.