Help using Base SAS procedures

assigning numberic statemetn to character observation and visa versa

Reply
N/A
Posts: 0

assigning numberic statemetn to character observation and visa versa

when using the if then statements, can you assign a character statemetn to a numberic variable adn visa versa?
N/A
Posts: 0

Re: assigning numberic statemetn to character observation and visa versa

Posted in reply to deleted_user
why would you want to do that?
N/A
Posts: 0

Re: assigning numberic statemetn to character observation and visa versa

Posted in reply to deleted_user
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.
SAS Super FREQ
Posts: 8,868

Re: assigning numberic statemetn to character observation and visa versa

Posted in reply to deleted_user
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
N/A
Posts: 0

Re: assigning numberic statemetn to character observation and visa versa

Posted in reply to Cynthia_sas
thankyou for the information. I will run it and see how it comes out.
Ask a Question
Discussion stats
  • 4 replies
  • 114 views
  • 0 likes
  • 2 in conversation