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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1148 views
  • 0 likes
  • 4 in conversation