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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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