- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I have a column in my data set called On Methadone . It has Yes or No as answer choices under the column. I wanted to make a new variable called Methadone with Yes = 1 and No = 2 .. I tried using iF then statement to do this but it didn't work.. and it seems its because there is a space between On and Methadone.
So I tried to remove the space by renaming the column by the following command:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If the name does not follow normal naming rules then you have to do two things.
1) Make sure the VALIDVARNAME option is set to ANY . (Or if you are talking about a dataset name that the VALIDMEMNAME option is set to EXTEND).
2) Use a NAME LITERAL in your code.
rename=("on methadone"n=methadone));
Name literals are like DATE literals only you use the letter N instead of the letter D after the quoted string.
Note that if the strange name was created by import an external file like an XLSX file or CSV file then you can avoid having SAS create such strange variable names by setting the VALIDVARNAME option to V7. Then PROC IMPORT will use valid variable names for the variables it creates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I do not recommend doing this.
Instead, use an underscore instead of a space and then add a descriptive label.
data work.import2;
set work.import (rename=(on_methadone=methadone));
label on_methadone = 'On Methadone';
run;
title 'Original Data Set';
proc print data=import (obs=10) noobs label;
var methadone;
run;
title 'New Data Set';
proc print data=import2(obs=10) noobs label;
var on_methadone;
run;
@manthan wrote:
Hello
I have a column in my data set called On Methadone . It has Yes or No as answer choices under the column. I wanted to make a new variable called Methadone with Yes = 1 and No = 2 .. I tried using iF then statement to do this but it didn't work.. and it seems its because there is a space between On and Methadone.
So I tried to remove the space by renaming the column by the following command:
data work.import;set work.import (rename=(on methadone=methadone));run;____________but I got the following error::79ERROR 79-322: Expecting a =.Can anyone help me here ? I think the On thing is making it confusing.. not sure though