BookmarkSubscribeRSS Feed
LauraFranziska
Calcite | Level 5

Hi,

I want to convert a already read in variable into a character - the opposite of e.g new_breed=breed*1

I am thankful for any help 🙂

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You cannot convert a numeric variable to character.

 

You can make a new character variable from a numeric variable.

 

char_var = put ( num_var, 5.);

or use whatever format works in your case

--
Paige Miller
LauraFranziska
Calcite | Level 5

Thanks for your help.

What is the 5 for?

Sorry, I'm new to SAS... 🙂

Cynthia_sas
SAS Super FREQ

Hi:
The 5. is a FORMAT -- it is the format that SAS uses to make the conversion. So, for example, if you have this zip=123 and you want to make charzip = 00123 as a character variable then you would use the z5. format, like this:
charzip = put(zip,z5.);

Or, if you have this: area=303 and you want this: char_area (303), then you would do:
char_area=catt('(',put(area,3.),')'); (concatenate the ( and ) with the character string 303 after the PUT function.

We teach about the PUT and INPUT functions and variable conversions in the Programming 2 class.

cynthia

andreas_lds
Jade | Level 19

new_breed=breed*1 triggers auto-converting "breed" to numeric so that the multiplication is possible. If you are sure, that an char-variable can be converted to numeric, use the input-function. That way you don't get tons of notes in the log and with the proper format you can convert non-english numbers to numbers.

 

Example:

data demo;
   a = '1.016,052';
   b = input(a, commax15.);
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 6732 views
  • 1 like
  • 4 in conversation