Help using Base SAS procedures

if then

Reply
Regular Contributor
Posts: 161

if then

Hello,

I need help in changing the first and 8th observation of my data, while leaving the rest unchanged.
using a simple
if obs=1 then s=1 s2=1 s3=1;
run;
does not work
Regular Contributor
Posts: 165

Re: if then

It should be :


if _N_=1 or _N_=8 then s=1 s2=1 s3=1;
run;

Good luck!
Regular Contributor
Posts: 161

Re: if then

thanks but it gives me the following error:

NOTE: Line generated by the invoked macro "MISQMATRIX".
1 data QMatrix; set Q_MATRIX_WR; IF _N_=1 or _N_=8 THEN skills1=1 skills2=1 skills3=1; run;

-------
-------

22
22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=,
<>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=,
|, ||, ~=.

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: 165

Re: if then

Sorry about that, you also need to use do;

data QMatrix;
set Q_MATRIX_WR;
IF _N_=1 or _N_=8 THEN do;
skills1=1;
skills2=1;
skills3=1;
end;
run;
Super Contributor
Posts: 394

Re: if then

[pre]
if _N_ = 1 or _N_ = 8 then do;
skills1=1;
skills2=1;
skills3=1;
end;
[/pre]
Regular Contributor
Posts: 161

Re: if then

Thank you Rick and Tim it WORKED!
R.A.G.
Frequent Contributor
Posts: 91

Re: if then

Or
if _N_ in (1,8) then do;
skills1=1;
skills2=1;
skills3=1;
end;
Ask a Question
Discussion stats
  • 6 replies
  • 157 views
  • 0 likes
  • 4 in conversation