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";

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 418 views
  • 1 like
  • 2 in conversation