BookmarkSubscribeRSS Feed
duanzongran
Obsidian | Level 7

dear all:

I know how to do one-hot encoding with data step.Is it possible to do it by using proc transpose?

79b91ef3efbc40aea8e69ab30c870186.png

data basic_info;
input name $ sex $;
datalines;
A Female
B Male
C Female
D Female
E Male
;
run;

Any sugesstion is welcome!

3 REPLIES 3
Ksharp
Super User
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;
Kurt_Bremser
Super User

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.

Reeza
Super User
And just a note, though you may already be aware, that if using certain procedures this is unnecessary as param=ref will do the encoding automatically.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 243 views
  • 1 like
  • 4 in conversation