BookmarkSubscribeRSS Feed
deleted_user
Not applicable
when using the if then statements, can you assign a character statemetn to a numberic variable adn visa versa?
4 REPLIES 4
deleted_user
Not applicable
this will make it easier to check the data once it has been run and make it easier to read for example i was trying to do this if age >= 1 and age < 4 then agegroup = toddler, but it didn't work.
Cynthia_sas
SAS Super FREQ
Hi:
You have a good idea. The way I would describe what you want to do is: create a new character variable or new category variable based on the VALUE of a numeric variable. Technically, you are not assigning a numeric statement to a character variable or a character value to a numeric variable.

There are 2 ways to do what you want:
1) is to create your own format and then use either the PUT function or INPUT function to create either a character or numeric variable
2) use a series of IF statements to assign a value to either a character or numeric variable.

There are some rules about creating variables. For example:
[pre]
newnumvar = 10; <-- numeric variable being created
newcharvar = 'Wombat'; <--character variable being created

OR

** NUMERIC variable AGECAT being created;
if age gt 0 and age lt 4 then agecat = 1;
else agecat = 2;

OR

** CHARACTER variable AGECAT2 being created;
if age gt 0 and age lt 4 then agecat2 = 'toddler ';
else agecat2 = 'pre-school';

[/pre]

Note that character variables are -usually- assigned quoted strings or assigned the values of other character variables. So when you had something like:
agegroup = toddler

SAS thought that toddler was a variable and you wanted to assign the value of the toddler variable to the new variable agegroup.

You might want to look in the documentation for the section about variables and how to create them and how to use them.

cynthia
deleted_user
Not applicable
thankyou for the information. I will run it and see how it comes out.

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
  • 626 views
  • 0 likes
  • 2 in conversation