BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dustychair
Pyrite | Level 9

Hi all,

I have a data set as below. I want to compare t and l1-3 and then assign a new variable called pl. When i do that i am getting a message saying that "Expecting an arithmetic operator" and underlies l1,l2,l3, and l4. What am i doing wrong?

 

Thanks
 

 

 

data set:

t l1 l2 l3 l4

-1.2 -1.2 0.5 0.2 0.1
-1.1 -1.2 0.5 0.2 0.1
-1.0 -1.2 0.5 0.2 0.1
-1.3 -1.2 0.5 0.2 0.1
-1.4 -1.2 0.5 0.2 0.1

 

data dd4;
set dd03;
	if t lt l1 then pl="Level 1";
	else if t ge l2 and lt l3 then pl="Level 2";
	else if t ge l3 and lt l4 then pl="Level 3";
	else if t ge l4 then pl="Level 4";
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Incorrect syntax.

 

else if t ge l2 and lt l3 then pl="Level 2";

Should be:

else if  l2 <= t < l3 then pl="Level 2";

Or more verbose

else if t ge l2 and t  lt l3 then pl="Level 2";

@dustychair wrote:

Hi all,

I have a data set as below. I want to compare t and l1-3 and then assign a new variable called pl. When i do that i am getting a message saying that "Expecting an arithmetic operator" and underlies l1,l2,l3, and l4. What am i doing wrong?

 

Thanks
 

 

 

data set:

t l1 l2 l3 l4

-1.2 -1.2 0.5 0.2 0.1
-1.1 -1.2 0.5 0.2 0.1
-1.0 -1.2 0.5 0.2 0.1
-1.3 -1.2 0.5 0.2 0.1
-1.4 -1.2 0.5 0.2 0.1

 

data dd4;
set dd03;
	if t lt l1 then pl="Level 1";
	else if t ge l2 and lt l3 then pl="Level 2";
	else if t ge l3 and lt l4 then pl="Level 3";
	else if t ge l4 then pl="Level 4";

 

View solution in original post

1 REPLY 1
Reeza
Super User

Incorrect syntax.

 

else if t ge l2 and lt l3 then pl="Level 2";

Should be:

else if  l2 <= t < l3 then pl="Level 2";

Or more verbose

else if t ge l2 and t  lt l3 then pl="Level 2";

@dustychair wrote:

Hi all,

I have a data set as below. I want to compare t and l1-3 and then assign a new variable called pl. When i do that i am getting a message saying that "Expecting an arithmetic operator" and underlies l1,l2,l3, and l4. What am i doing wrong?

 

Thanks
 

 

 

data set:

t l1 l2 l3 l4

-1.2 -1.2 0.5 0.2 0.1
-1.1 -1.2 0.5 0.2 0.1
-1.0 -1.2 0.5 0.2 0.1
-1.3 -1.2 0.5 0.2 0.1
-1.4 -1.2 0.5 0.2 0.1

 

data dd4;
set dd03;
	if t lt l1 then pl="Level 1";
	else if t ge l2 and lt l3 then pl="Level 2";
	else if t ge l3 and lt l4 then pl="Level 3";
	else if t ge l4 then pl="Level 4";

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 961 views
  • 1 like
  • 2 in conversation