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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.