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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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