BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jweinstein2001
Calcite | Level 5

Within my data imported, I have a variable titled " Transmission Type", which I reference within the code. Yet when referenced its ignored and the newvar is only given the value 1. I have tried this without creating a new variable using then put and it still doesn't notice the reference to the variable. What in my pathway is not allowing for the code to recognize the variable?

libname Ec351 "/home/u59307513/Ec351";
proc import datafile='/home/u59307513/Ec351/CarPrice Regression Dataset Ec351.xls' dbms=xls out=EC351.Project1 replace;
getnames=yes;
run;


data ec351.projectsorted;
set ec351.project1;
options validvarname=any;
if year < 2017 then delete;
run;

data ec351.projectuseabledata ; 
set ec351.projectsorted;
if "Transmission Type" = 'manual' then Newvar = '0';
else Newvar = '1' ;
drop year; 
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
if "Transmission Type"n = 'manual' then Newvar = 0;

There are no rows where the value of "Transmission Type"n is equal to 'manual'

There are many rows where the value of "Transmission Type"n is equal to 'MANUAL'

 

'manual' is not the same as 'MANUAL'

--
Paige Miller

View solution in original post

15 REPLIES 15
PaigeMiller
Diamond | Level 26

With VALIDVARNAME=ANY, you need to append the letter n to the variable name after the single or double quote at the end

 

if "Transmission Type"n = 'manual' then Newvar = '0';

  


As a side issue, when creating new variables which can have the value 0 or 1, make this a numeric variable, not a character variable. Numeric variable are easier to work with, and also you have a lower chance of a typographical error typing zero or 1, then typing the value in quotes.

 

 

if "Transmission Type"n = 'manual' then Newvar = 0;

 

 

--
Paige Miller
Jweinstein2001
Calcite | Level 5

When doing this the value of my variable is always 1 even though it shouldn't be. For some reason its not recognize the variable still. Having the same problem when trying to reference my City MPG variables and along with my Highway MPG variable.

 

libname Ec351 "/home/u59307513/Ec351";
proc import datafile='/home/u59307513/Ec351/CarPrice Regression Dataset Ec351.xls' dbms=xls out=EC351.Project1 replace;
getnames=yes;
run;


data ec351.projectsorted;
set ec351.project1;
options validvarname=any;
if year < 2017 then delete;
run;

data ec351.projectuseabledata ; 
set ec351.projectsorted;
if "Transmission Type"n = 'manual' then Newvar = 0;
else Newvar = 1 ;
drop year; 
AvgMPG = (("City_MPG"+"Highway_MPG")/2);
run;
PaigeMiller
Diamond | Level 26

Did you look at SAS data set ec351.project1 to see if this variable is ever equal to 'manual' ??? What do you see?

 

Having the same problem when trying to reference my City MPG variables and along with my Highway MPG variable.

 

Don't put these variable names in quotes. Quotes followed by the letter n are only needed for variable names that don't conform to the SAS variable naming rules.

--
Paige Miller
Jweinstein2001
Calcite | Level 5

I linked the dataset, the value is different and should be changing, I've ran into this problem before even though I feel as if I'm doing everything correctly.

PaigeMiller
Diamond | Level 26

@Jweinstein2001 wrote:

I linked the dataset, the value is different and should be changing, I've ran into this problem before even though I feel as if I'm doing everything correctly.


But I specifically asked if you looked at this data set to see if any of the records had a value of 'manual'. What did you see?

--
Paige Miller
Jweinstein2001
Calcite | Level 5
Yes ive looked, I created the dataset and it has hundreds that are manual and hundreds that arent. With my code it should be changing these values to 0.
PaigeMiller
Diamond | Level 26

@Jweinstein2001 wrote:
Yes ive looked, I created the dataset and it has hundreds that are manual and hundreds that arent. With my code it should be changing these values to 0.

I (and most people here) refuse to download Excel files or any Microsoft Office files. Make a screen capture, and include it using the "Insert Photos" icon. Do not attach files.

--
Paige Miller
PaigeMiller
Diamond | Level 26
if "Transmission Type"n = 'manual' then Newvar = 0;

There are no rows where the value of "Transmission Type"n is equal to 'manual'

There are many rows where the value of "Transmission Type"n is equal to 'MANUAL'

 

'manual' is not the same as 'MANUAL'

--
Paige Miller
Jweinstein2001
Calcite | Level 5
Even when I change the value to all caps, the same outcome occurs.
Jweinstein2001
Calcite | Level 5
Sorry, I found the issue, it's saying NOTE: VARCHAR data type is not supported by the V9 engine. Variable Transmission Type has been converted to CHAR data type. After opening up my options it's tells me it's changing the data type, how would I now make this usable datatype?
Jweinstein2001
Calcite | Level 5
also if I dont use quotes it creates new variable for the highway and city, how do I avoid this while referencing them?
PaigeMiller
Diamond | Level 26

@Jweinstein2001 wrote:
Sorry, I found the issue, it's saying NOTE: VARCHAR data type is not supported by the V9 engine. Variable Transmission Type has been converted to CHAR data type. After opening up my options it's tells me it's changing the data type, how would I now make this usable datatype?

 

Show us the ENTIRE log for this sequence of code, so we can see what you see. Copy the log as text, paste it into the window that appears when you click on the </> icon.

PaigeMiller_0-1663012019648.png

 

--
Paige Miller
Jweinstein2001
Calcite | Level 5
 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result.
       38:1     RC
 68         
 69         options MSGLEVEL=I;
 70         libname Ec351 "/home/u59307513/Ec351";
 NOTE: Libref EC351 was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /home/u59307513/Ec351
 71         proc import datafile='/home/u59307513/Ec351/CarPrice Regression Dataset Ec351.xls' dbms=xls out=EC351.Project1 replace;
 72         getnames=yes;
 73         run;
 
 NOTE: VARCHAR data type is not supported by the V9 engine. Variable Transmission Type has been converted to CHAR data type.
 NOTE: The import data set has 11914 observations and 7 variables.
 NOTE: EC351.PROJECT1 data set was successfully created.
 NOTE: PROCEDURE IMPORT used (Total process time):
       real time           0.03 seconds
       user cpu time       0.01 seconds
       system cpu time     0.01 seconds
       memory              3242.68k
       OS Memory           36324.00k
       Timestamp           12/05/2022 08:23:43 PM
       Step Count                        524  Switch Count  2
       Page Faults                       0
       Page Reclaims                     669
       Page Swaps                        0
       Voluntary Context Switches        50
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           1544
       
 
 74         
 75         
 76         data ec351.projectsorted;
 77         set ec351.project1;
 78         options validvarname=any;
 79         if year < 2017 then delete;
 80         run;
 
 NOTE: There were 11914 observations read from the data set EC351.PROJECT1.
 NOTE: The data set EC351.PROJECTSORTED has 1668 observations and 7 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.02 seconds
       user cpu time       0.01 seconds
       system cpu time     0.00 seconds
       memory              1605.50k
       OS Memory           34740.00k
       Timestamp           12/05/2022 08:23:43 PM
       Step Count                        525  Switch Count  2
       Page Faults                       0
       Page Reclaims                     260
       Page Swaps                        0
       Voluntary Context Switches        61
       Involuntary Context Switches      0
       Block Input Operations            1568
       Block Output Operations           264
       
 
 81         
 82         data ec351.projectuseabledata ;
 83         set ec351.projectsorted;
 84         if "Transmission Type"n = 'manual' then Newvar = 0;
 85         else Newvar = 1 ;
 86         drop year;
 87         AvgMPG = ((City_MPG+Highway_MPG)/2);
 88         run;
 
 NOTE: Variable Highway_MPG is uninitialized.
 NOTE: Variable City_MPG is uninitialized.
 NOTE: Missing values were generated as a result of performing an operation on missing values.
       Each place is given by: (Number of times) at (Line):(Column).
       1668 at 87:20   
 NOTE: There were 1668 observations read from the data set EC351.PROJECTSORTED.
 NOTE: The data set EC351.PROJECTUSEABLEDATA has 1668 observations and 10 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.02 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              1171.81k
       OS Memory           34228.00k
       Timestamp           12/05/2022 08:23:43 PM
       Step Count                        526  Switch Count  1
       Page Faults                       0
       Page Reclaims                     97
       Page Swaps                        0
       Voluntary Context Switches        53
       Involuntary Context Switches      0
       Block Input Operations            288
       Block Output Operations           520
       
 
 89         
 90         
 91         
 92         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 102        

Thank you very much by the way.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 1996 views
  • 0 likes
  • 3 in conversation