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

I got 2 errors below under if and index, could anyone tell me how to correct it? I greatly appreciate your help!

data cc;
input status T1 T2 index;
cards;
4 0 1 .
6 2 1 .
. 0 0 .
;
run;

if status <=5 then output;
index =(2 * T1) + T2;
proc print;
run;

 

if status <=5 then output;
__
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
index =(2 * T1) + T2;
_____
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Your statements don't refer to a input data set they're in the middle of your code. 

You need to wrap that in a data step. 

You're also reading 4 data points, status, T1, T2 and Index but have no values for index? Any particular reason for that? I could see that causing issues. 

 

I would also very strongly recommend referencing the data set you want to print in PROC PRINT via DATA= so it's explicit otherwise by default it prints the last data set but if you had an error in your code, that may not be the data set you wanted to see. 

 

 

data cc;
input status T1 T2 index; 
cards;
   4	          0             1 .
   6              2             1 .
   .              0             0 .
;
run;

data cc2;
set cc;
if status <=5 then output;
index =(2 * T1) + T2;
run;

title 'Data set after import';
proc print data=cc;
run; 

title 'Data set after calculation';
proc print data=cc2;
run; 

@Amy0223 wrote:

I got 2 errors below under if and index, could anyone tell me how to correct it? I greatly appreciate your help!

data cc;
input status T1 T2 index;
cards;
4 0 1 .
6 2 1 .
. 0 0 .
;
run;

if status <=5 then output;
index =(2 * T1) + T2;
proc print;
run;

 

if status <=5 then output;
__
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
index =(2 * T1) + T2;
_____
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.

 


 

View solution in original post

6 REPLIES 6
Reeza
Super User

Your statements don't refer to a input data set they're in the middle of your code. 

You need to wrap that in a data step. 

You're also reading 4 data points, status, T1, T2 and Index but have no values for index? Any particular reason for that? I could see that causing issues. 

 

I would also very strongly recommend referencing the data set you want to print in PROC PRINT via DATA= so it's explicit otherwise by default it prints the last data set but if you had an error in your code, that may not be the data set you wanted to see. 

 

 

data cc;
input status T1 T2 index; 
cards;
   4	          0             1 .
   6              2             1 .
   .              0             0 .
;
run;

data cc2;
set cc;
if status <=5 then output;
index =(2 * T1) + T2;
run;

title 'Data set after import';
proc print data=cc;
run; 

title 'Data set after calculation';
proc print data=cc2;
run; 

@Amy0223 wrote:

I got 2 errors below under if and index, could anyone tell me how to correct it? I greatly appreciate your help!

data cc;
input status T1 T2 index;
cards;
4 0 1 .
6 2 1 .
. 0 0 .
;
run;

if status <=5 then output;
index =(2 * T1) + T2;
proc print;
run;

 

if status <=5 then output;
__
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
index =(2 * T1) + T2;
_____
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.

 


 

Amy0223
Quartz | Level 8

Thank you so much! I understand it now.  I greatly appreciate your quick response!Smiley Very Happy

novinosrin
Tourmaline | Level 20

HI @Amy0223  Are you after this?

 

data cc;
input status T1 T2 ; 

index =(2 * T1) + T2;

if status <=5 and not missing(status) then output;
cards;
   4	          0             1 .
   6              2             1 .
   .              0             0 .
;
run;
Amy0223
Quartz | Level 8

Thank you very much for your help! I got errors because I didn't set cc

data cc2;
set cc;

 

Kurt_Bremser
Super User

A data step with cards or datelines ends right there, what follows is data, and when that ends, you have the step boundary. You also don't need a run; to create the step boundary.

You can incorporate your other statements into the data step, though:

data cc;
input status T1 T2;
if status <= 5;
index = (2 * T1) + T2;
cards;
   4	          0             1
   6              2             1
   .              0             0
;

Mind that I omitted the output statement, because it would have prevented the calculation from having an effect on the output.

 

Amy0223
Quartz | Level 8
Thank you very much for taking the time to answer my question. It's really helpful 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 1659 views
  • 6 likes
  • 4 in conversation