0
votes

I have created the following SAS table:

DATA test;
INPUT name$ Group_Number;
CARDS;
Joseph 1
Stephanie 2
Linda 3
James 1
Jane 2; 
run;

I would like to change group number from a character type into a numeric type.

Here is my attempt:

data test2;
set test;
Group_Number1 = input(Group_Number, best5.);
run;

The problem is that when I execute:

proc contents data = test2; 
run;

The output table shows that group number is still of a character type. I think that the problem may be that I have "best5." in my input statement. However I am not 100% sure what is wrong.

How can I fix the solution?

2
You list three variables, name, group and number but only have two in the data step? Did you run it to make sure it works?Reeza
@Reeza Apologies. Group_Number should be one word! I have changed it nowJed
Did you run it? It didn't work for me again. Instructions on creating a data step can be found here if you have difficulties with it: communities.sas.com/t5/SAS-Communities-Library/…Reeza
The reason I'm harping on this, once you have it read correctly, it's read as numeric and your question is irrelevant.Reeza
@Reeza So it does read as numeric as you are saying. However when I look into the table "test2", the Group_Number1 column is empty. Do you not have the same also?Jed

2 Answers

0
votes

If you have a character variable your code will work. But you don't, you have a numeric variable in your sample data. So either your fake data is incorrect, or you don't have the problem you think you do.

Here's an example that you can run to see this.

*read group_number as numeric;
DATA test_num;
INPUT name$ Group_Number;
CARDS;
Joseph 1
Stephanie 2
Linda 3
James 1
Jane 2
; 
run;

Title 'Group_Number is Numeric!';
proc contents data=test;
run;

*read group_number as character;
DATA test_char;
INPUT name$ Group_Number $;
CARDS;
Joseph 1
Stephanie 2
Linda 3
James 1
Jane 2
; 
run;

data test_converted;
set test_char;
    group_number_num = input(group_number, 8.);
run;

Title 'Group_Number is Character, Group_Number1 is Numeric';
proc contents data=test_converted;
run;
0
votes

try this:

data test2;
set test;
Group_Number1 = input(put(Group_Number,best5.),best5.);
run;