BookmarkSubscribeRSS Feed
capam
Pyrite | Level 9

The following code works as expected.

 

data have;
	set have;
	by veh_no;

	if veh_no="&num" then
		do;
			if var1 ne '0' then
				do;
					if first.var1 then
						cusumvar1=0;
					cusumvar1+1;
				end;
		end;
run;

However, when I add a similar if then loop I get an error message. 

 

ERROR 22-322: Syntax error, expecting one of the following: (, +, =.

 

data have;
	set have;
	by veh_no;

	if veh_no="&num" then
		do;
			if var1 ne '0' then
				do;
					if first.var1 then
						cusumvar1=0;
					cusumvar1+1;
				end;

			if var2 ne '0' then
				do;
					if first.var2 then
						cusumvar2=0;
					cusumvar2+1;
				end;
		end;
run;
2 REPLIES 2
Astounding
PROC Star

A few notes might help push you in the right direction ...

 

First, don't use DATA HAVE; SET HAVE; when you are experimenting and trying to get a program to work.  If an experiment fails (but doesn't generate an error message), you will have replaced your data with a poor substitute.

 

Second, either you didn't show the code you ran, or your expectations are bizarre.  There is no way the top program ran "as expected" when you include this combination of statements:

 

BY VEH_NO;

IF FIRST.VAR1 THEN ...

 

The program doesn't create FIRST.VAR1.  At a minimum, the log should give you a message to that effect.

 

Finally, is this code part of a macro?  If not, you should be able to pinpoint in the log which statement the error message refers to.

andreas_lds
Jade | Level 19

When debugging programs with macro-variables always turn on options mprint and symbolgen. Posting the log will make debugging easier, because without your data we are unable to reproduce the problem you have.

 

There is an error in your first data-step, you can't use 

first.var1

without having var1 in the BY-statement.

 

The if-then-statement is not a loop 😉

 

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
  • 2 replies
  • 695 views
  • 2 likes
  • 3 in conversation