Programming the statistical procedures from SAS

IF THEN

Reply
Regular Contributor
Posts: 161

IF THEN

Hi,
I was wondering why my code does not work.

Thank you


DATA QMATRIX;
SET QMATRIX;
array itematt(3);
do i=1 to 3;
IF ITEM=1 THEN itematt&i=1;
END;
drop i;
run;

ERROR:


180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
MPRINT(MISQMATRIX): data qmatrix;
MPRINT(MISQMATRIX): set qmatrix;
MPRINT(MISQMATRIX): IF ITEM=1 THEN itematt1-itematt3=1 ;
MPRINT(MISQMATRIX): Run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.QMATRIX may be incomplete. When this step was stopped there were 0
observations and 4 variables.
WARNING: Data set WORK.QMATRIX was not replaced because this step was stopped.
Regular Contributor
Posts: 241

Re: IF THEN

The log reports that your if statement resolves to:
> IF ITEM=1 THEN itematt1-itematt3=1 ;
which is incorrect.
Regular Contributor
Posts: 161

Re: IF THEN

thanks, I changed the syntax to this and still it does not run.

%macro MISQMATRIX;
%let num_skills=3;

DATA Q_MATRIX_WR;
set QMatrix;
array skills(&num_skills);

do i=1 to &num_skills;
IF question=1 THEN skills1=1 skills2=1 skills3=1;
ELSE
skills(i)=1- skills(i);
END;
drop i;
run;
%mend;

ERROR:
NOTE 137-205: Line generated by the invoked macro "MISQMATRIX".
1 DATA Q_MATRIX_WR; set QMatrix; array skills(&num_skills); do i=1 to &num_skills; IF
1 ! question=1 THEN skills1=1 skills2=1 skills3=1; ELSE skills(i)=1- skills(i); END; drop i;
-------
22
1 ! run;
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=,
<>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=,
|, ||, ~=.

MPRINT(MISQMATRIX): do i=1 to 3;
NOTE 137-205: Line generated by the invoked macro "MISQMATRIX".
1 DATA Q_MATRIX_WR; set QMatrix; array skills(&num_skills); do i=1 to &num_skills; IF
1 ! question=1 THEN skills1=1 skills2=1 skills3=1; ELSE skills(i)=1- skills(i); END; drop i;
-------
22
1 ! run;
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=,
<>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=,
|, ||, ~=.

MPRINT(MISQMATRIX): IF question=1 THEN skills1=1 skills2=1 skills3=1 ;
MPRINT(MISQMATRIX): ELSE skills(i)=1- skills(i);
MPRINT(MISQMATRIX): END;
MPRINT(MISQMATRIX): drop i;
MPRINT(MISQMATRIX): run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.Q_MATRIX_WR may be incomplete. When this step was stopped there were
0 observations and 4 variables.
Trusted Advisor
Posts: 2,114

Re: IF THEN

You are mixing up array syntax and macro syntax.

array itematt(3);
do i=1 to 3;
IF ITEM=1 THEN itematt&i=1;
END;
uses the macro variable "i" (undefined), as well as an incorrect type of "container" on the ARRAY statement itself.

Change the syntax
array itematt{3};
do i=1 to 3;
IF ITEM=1 THEN itematt{i}=1;
END;
Note the {...} "container".
Super Contributor
Super Contributor
Posts: 3,174

Re: IF THEN

Curious how this post fits into the Statistical Procedures forum?

Suggest you get rid of the macro and get your standalone SAS DATA step working before making it more flexible with macro language elements. Substitute constants (or if absolutely necessary use static macro variables).

Scott Barry
SBBWorks, Inc.
Regular Contributor
Posts: 161

Re: IF THEN

Thank you Doc, It is always great to read constructive comment vs. criticism of our lack of knowledge.
Ask a Question
Discussion stats
  • 5 replies
  • 3375 views
  • 0 likes
  • 4 in conversation