BookmarkSubscribeRSS Feed
trekvana
Calcite | Level 5
hello all-

say i have a character variable x=(a,a,a,a,c,c,b,b,b,d,d,e) how can i convert this to y=(1,1,1,1,2,2,3,3,3,4,4,5).

ive tried the input command but im not sure how to use this. im assuming there must be an easy way to do this

cheers
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Look at using the TRANSLATE function - you will need to define argument2 and argument3 with the value mapping/associations.

Scott Barry
SBBWorks, Inc.
SASKiwi
PROC Star
I would be inclined to create an custom INFORMAT to do this:

proc format;
invalue alpha_order 'A' = 1;
run;

data test;
var = 'A';
var_order = input(var, alpha_order.);
put _all_;
run;

You could expand this example to cover all 26 alphabet letters, or write a DATA step to generate a PROC FORMAT input dataset automatically.
Ksharp
Super User
Just as SBB said.Try this.
[pre]
data a;
input x $;
datalines;
a
a
a
a
c
c
b
b
b
d
d
e
;

data b;
set a;
_x=translate(x,'12345','abcde');
run;
proc print;
run;
[/pre]



Ksharp

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1303 views
  • 0 likes
  • 4 in conversation