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;
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;__180ERROR 180-322: Statement is not valid or it is used out of proper order.index =(2 * T1) + T2;_____180ERROR 180-322: Statement is not valid or it is used out of proper order.
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;__180ERROR 180-322: Statement is not valid or it is used out of proper order.index =(2 * T1) + T2;_____180ERROR 180-322: Statement is not valid or it is used out of proper order.
Thank you so much! I understand it now. I greatly appreciate your quick response!
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;
Thank you very much for your help! I got errors because I didn't set cc
data cc2; set cc;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.