New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
manthan
Fluorite | Level 6

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::
79
ERROR 79-322: Expecting a =.
 
Can anyone help me here ? I think the On thing is making it confusing.. not sure though
 

 

2 REPLIES 2
Tom
Super User Tom
Super User

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.

Reeza
Super User

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::
79
ERROR 79-322: Expecting a =.
 
Can anyone help me here ? I think the On thing is making it confusing.. not sure though
 

 


 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1196 views
  • 0 likes
  • 3 in conversation