- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I would appreciate some assistance in converting variables that have imported as categorical to numeric. I intend to drop the variables read as categorical, and keep the name of the variable for the numeric variable. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Examples of the values involved will help.
Generally I suggest going back to how the data was read and modify the approach to ensure the desired results start as intended. Several of the reasons that data that should be numeric end up as character also cutoff the values and may mean that converting the character values are not actually what is wanted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Agreeing with @ballardw , the best approach is to fix the way the variables are created in the first place, it seems as if something is broken there.
Variables cannot be converted from categorical to numeric (without some trickery). Easiest to create a new numeric variable with a new name that will hold the numeric values.
data example;
charvar = '123548';
numvar = input(charvar, 8.);
run;
Version with trickery:
data have;
vaccuum='123548';
run;
data want;
set have(rename=(vaccuum=vaccuum_old));
vaccuum = input(vaccuum_old, 8.);
drop vaccuum_old;
run;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SAS doesn't contain categorical variables. It contains only numeric variables and character variables. Certainly it is possible to have variables that contain only a limited number of values. But they are still either numeric or character once they are imported.
Give a specific example of what you intend as the before and after result, and you are sure to get further guidance.