DATA Step, Macro, Functions and more

Numeric to character within data step

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Numeric to character within data step

I have something like

data one;

merge dataset1 dataset2;

.................

if var=1 then var='large';

else var='small';

run;

Now, the variable var is extracted from datasets 1 and 2 with a numeric format;however 'large' and 'small' are character and this generates errors.

How can I transform from numeric to character within the data step as created above?

I tried adding "format var $6.;" but this did not solve the problem.


Accepted Solutions
Solution
‎10-13-2013 06:31 PM
Super User
Super User
Posts: 7,060

Re: Numeric to character within data step

proc format ;

value size 1='large' other='small';

run;

proc sgplot;

by var;

format var size. ;

run;

View solution in original post


All Replies
PROC Star
Posts: 7,474

Re: Numeric to character within data step

Do you really want to assign new values?  Or, on the other hand, do you simply want the character values to appear in lists, reports and or analyses?  If it is the latter, you can create and assign a format.

Contributor
Posts: 20

Re: Numeric to character within data step

I want to use the variable in

proc sgplot;

by var;

So yes, I do no necessarily need to assign new values, but I need more info.

Solution
‎10-13-2013 06:31 PM
Super User
Super User
Posts: 7,060

Re: Numeric to character within data step

proc format ;

value size 1='large' other='small';

run;

proc sgplot;

by var;

format var size. ;

run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 249 views
  • 3 likes
  • 3 in conversation