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

I am attempting to use the month() function to extract the month from a date variable formatted as MONYY7 read from an xlsx file. It is returning the following error:

 
 
num_mon = month(date);
_______
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Ok, that's not how you create a new variable. 

 

If you want to calculate a month you need to create a new variable within a data step. 

 

See a tutorial here or the code below:

http://video.sas.com/detail/videos/sas-analytics-u/video/4573023399001/creating-a-new-column-in-sas?...

 

data calculate_month; *create a new data set called calculate_month;
set one; *data set imported in previous step;

month_num = month(date); *calculate month;

run;

View solution in original post

4 REPLIES 4
Reeza
Super User

Where's the rest of the code?

 

Post the log and error as well please. 

 


@nelsondn wrote:

I am attempting to use the month() function to extract the month from a date variable formatted as MONYY7 read from an xlsx file. It is returning the following error:

 
 
num_mon = month(date);
_______
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 

 

nelsondn
Calcite | Level 5

The code: 

 

options ls=78 formdlim='*';
ods listing;
proc import OUT= work.one
DATAFILE= "/home/nelsondn0/sasuser.v94/Gasoline.xlsx" DBMS=XLSX REPLACE; GETNAMES=YES;
run;

num_mon = month(date);

 

 
 
Log and error: 
 
num_mon = month(date);
_______
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
Reeza
Super User

Ok, that's not how you create a new variable. 

 

If you want to calculate a month you need to create a new variable within a data step. 

 

See a tutorial here or the code below:

http://video.sas.com/detail/videos/sas-analytics-u/video/4573023399001/creating-a-new-column-in-sas?...

 

data calculate_month; *create a new data set called calculate_month;
set one; *data set imported in previous step;

month_num = month(date); *calculate month;

run;
nelsondn
Calcite | Level 5
Worked perfectly, thank you!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 702 views
  • 0 likes
  • 2 in conversation