Transforming numeric to character variable

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Transforming numeric to character variable

Dear All;

I have the following dataset:

data have;

input ID Var;

datalines;

10     550     

20     440        

;


where Var is a numeric variable, I would like to transform it to a character variable and obtain the following

data want;

input ID Var;

datalines;

10     5-50     

20     4-40        

;


This my unsuccessful attempt:


data want;

set have;

Var1 = put(Var,10.);

run;

data want; set want;

if Var1 = '550' then Var1 = '5-50';

if Var1 = '440' then Var1 = '4-40';

run;


Any help would be highly appreciated.


Accepted Solutions
Solution
‎02-27-2015 04:06 PM
Super User
Posts: 17,750

Re: Transforming numeric to character variable

Change your put statement to use the -l option, it will align your variable to the left.

For your conversion you may want to use substr/catt functions instead of harding it.

Var1 = put(Var,10. -l);

View solution in original post


All Replies
Solution
‎02-27-2015 04:06 PM
Super User
Posts: 17,750

Re: Transforming numeric to character variable

Change your put statement to use the -l option, it will align your variable to the left.

For your conversion you may want to use substr/catt functions instead of harding it.

Var1 = put(Var,10. -l);

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 154 views
  • 0 likes
  • 2 in conversation