I have a column of data with the following attributes:
Data Set Name: WORK.IMPORT
Variable: Kill_wt
Type: Char
Len: 14
Format: $14
Informat: $14
Label: Kill wt
These data are continuous numerical data, but SAS doesn't see it this way. I tried the following command from a Youtube video to try and correct this:
data WORK.IMPORT2; set WORK.IMPORT;
* Convert Kill_wt from character to numeric;
Kill_wt = input(Kill_wt, best12.);
run;
No errors show up when I run this, but nothing changes. How can I change the format/informat for "Kill_wt" from $14(character) to BEST12(this is what all my numerical data in the set are set as)? Please explain it to me like I have only been using SAS for a week (I have).
Thanks!
Editor's Note: This post is among the most visited in these forums! In addition to the help provided below, here's a tutorial that walks you through what to do in about 9 minutes:
Your code is correct, with one major issue, you can't convert a variable from text to numeric and keep the same name.
That would be changing the variable type on the fly and SAS doesn't support that.
So...either rename the original variable on your SET statement or your calculated variable.
kill_wt2 = input(kill_wt, best12.)
This SAS Note contains lots of helpful advice for converting data types in SAS:
Editor's Note: This post is among the most visited in these forums! In addition to the help provided below, here's a tutorial that walks you through what to do in about 9 minutes:
Your code is correct, with one major issue, you can't convert a variable from text to numeric and keep the same name.
That would be changing the variable type on the fly and SAS doesn't support that.
So...either rename the original variable on your SET statement or your calculated variable.
kill_wt2 = input(kill_wt, best12.)
This SAS Note contains lots of helpful advice for converting data types in SAS:
Thanks Reeza, but I tried that to no avail. Any other ideas? Could it be how I imported the data from .xls?
Post your code, log and proc contents from new data set. That should have worked.
/* Generated Code (IMPORT) */
/* Source File: Aspirin field trial.xls */
/* Source Path: /folders/myfolders */
/* Code generated on: Thursday, January 28, 2016 3:26:09 AM */
%web_drop_table(WORK.IMPORT);
FILENAME REFFILE "/folders/myfolders/Aspirin field trial.xls" TERMSTR=CR;
PROC IMPORT DATAFILE=REFFILE
DBMS=XLS
OUT=WORK.IMPORT;
GETNAMES=YES;
RUN;
PROC CONTENTS DATA=WORK.IMPORT; RUN;
%web_open_table(WORK.IMPORT);
data WORK.IMPORT2; set WORK.IMPORT;
* Convert kill_wt from character to numeric;
Lung_wt2 = input(Lung_wt, best9.);
run;
Your last step references import not the new data set you created, import2.
Change it to refer to import2 and change the select to include lung_wt2.
Basically you created the correct dataset but didn't use it in your next steps, but went back to the original dataset.
Manually check the data set import2 -> open it in the editor.
proc sql, the last step.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Ready to level-up your skills? Choose your own adventure.