BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JibJam221
Obsidian | Level 7

Hi all,

 

im having some issues changing one of my variables from Character ($CHAR1.) to numeric (BEST12.) so that I can append it to another table. The variable's format that im trying to change is a pre-existing variable within the dataset.

 

Here is my current code:

 

data work.test2;
set work.test;
SYD=input(SYD,BEST12.);
run;

 

when I run this code, I dont get any errors or warnings however the variable doesn't change formats.

 

Any suggestions on what I can do?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Variables can't change their type.  But you can work around it:

 

data work.test2;
   set test;
   newvar = input(SYD, best12.);
   drop SYD;
   rename newvar = SYD;
run;

View solution in original post

4 REPLIES 4
Astounding
PROC Star

Variables can't change their type.  But you can work around it:

 

data work.test2;
   set test;
   newvar = input(SYD, best12.);
   drop SYD;
   rename newvar = SYD;
run;
JibJam221
Obsidian | Level 7
it worked! Thank you!!!
japelin
Rhodochrosite | Level 12

Is the following NOTE being output to the log?

japelin_0-1652754165052.png

This means that an implicit conversion is taking place because the result of converting SYD to a number with the input function is stored in a character variable.
Since SAS does not allow variable type change, rename is required as follows.

 

data work.test2(drop=_SYD);
  set work.test(rename=(SYD=_SYD));
  SYD=input(_SYD,BEST12.);
run;

 

 

JibJam221
Obsidian | Level 7
I also tried this and it worked as well! Thank you so much

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 966 views
  • 0 likes
  • 3 in conversation