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

Hello Team,

 

I've the following code in my program and it is giving me the below error when I run. Please help. Please note that I'm trying to create a new column by multiplying 0.0085 to the column 10th Feb 2021.

 

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

data mynewdata;
set WORK.IMPORT;
10Feb_CAD=10th Feb 2021*0.0085;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@mithqueens wrote:

Hello Team,

 

I've the following code in my program and it is giving me the below error when I run. Please help. Please note that I'm trying to create a new column by multiplying 0.0085 to the column 10th Feb 2021.

 

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

data mynewdata;
set WORK.IMPORT;
10Feb_CAD=10th Feb 2021*0.0085;
run;


When you get an error best practice is to copy the code with the error messages and other notes for the entire data step or procedure from the log. The on the forum as part of your question open a text box using the </> icon and paste the text.

If you look at your log you will see that error message comes with diagnostic characters that underline where SAS found the objectionable syntax element(s).

 

With that in mind, SAS standard variable names start with either a letter or the underscore character followed by letters, digits or underscores. Your 10Feb_CAD, is not a valid standard SAS variable name. If you have name that looks like that because you allowed Proc Import or similar to create one with the option validvarname=any then what you have is called a "name literal". To use it in code you would have to use "10Feb_cad"n, the quotes and letter n tell SAS that you have a non-standard variable name.

With your code I can't tell if you expect to have date value of 10th Feb 2021 or if that is supposed to be another variable name. If it is a variable name then again you would use "10th Feb 2021"n to reference the variable name.

 

BTW having data values, such as a date, in the name of a variable often makes for complex and difficult to maintain or modify code.

View solution in original post

4 REPLIES 4
ballardw
Super User

@mithqueens wrote:

Hello Team,

 

I've the following code in my program and it is giving me the below error when I run. Please help. Please note that I'm trying to create a new column by multiplying 0.0085 to the column 10th Feb 2021.

 

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

data mynewdata;
set WORK.IMPORT;
10Feb_CAD=10th Feb 2021*0.0085;
run;


When you get an error best practice is to copy the code with the error messages and other notes for the entire data step or procedure from the log. The on the forum as part of your question open a text box using the </> icon and paste the text.

If you look at your log you will see that error message comes with diagnostic characters that underline where SAS found the objectionable syntax element(s).

 

With that in mind, SAS standard variable names start with either a letter or the underscore character followed by letters, digits or underscores. Your 10Feb_CAD, is not a valid standard SAS variable name. If you have name that looks like that because you allowed Proc Import or similar to create one with the option validvarname=any then what you have is called a "name literal". To use it in code you would have to use "10Feb_cad"n, the quotes and letter n tell SAS that you have a non-standard variable name.

With your code I can't tell if you expect to have date value of 10th Feb 2021 or if that is supposed to be another variable name. If it is a variable name then again you would use "10th Feb 2021"n to reference the variable name.

 

BTW having data values, such as a date, in the name of a variable often makes for complex and difficult to maintain or modify code.

mithqueens
Calcite | Level 5

Hi Ballardw,

 

Thank you so much for that feedback. I was able to resolve the problem. Glad to be part of this community.

Tom
Super User Tom
Super User

What is the name of the variable for the "column" labeled "10th Feb 2021"?

mithqueens
Calcite | Level 5

Hi Tom,

 

Thank you for offering the help. I was able to solve the problem. There's was an issue with how I was trying to name the variable.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 723 views
  • 1 like
  • 3 in conversation