BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MirLuie
Calcite | Level 5

Hey Guys!

 

sorry for my english.. i try my best 🙂

 

Does someone know, how to select all data from my table:

 

between (AE = "A" AND AE = "E")  OR between (AE = "A" AND AE = "B")   OR  between (AE = "B" AND AE = "E") OR  between (AE = "B" AND AE = "B")

 

There are As for Start, Es for End or Bs for either Start or End in the data set.

I just like to select the rows between an A and an E (or A and B or B and E or even B and B) and put them in a new table.

so like: when AE is A: take all lines after (in time) until AE is E and put them in a new table

 

Table is sorted by IPID and than by measurement_time.

 

please look at the pic attached.

 

 

thank you very much!

Luie

 

tabletable

 

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

Untested; when you post a question like this, you should provide your test data in the form of a data step, so I can recreate it to try the program;

 

Tom

 

data SetSwitch;
	retain KeepSwitch 0;
	set Have;

	if AE = "A" then KeepSwitch = 1;
	else if AE = "E" then KeepSwitch = 0;
	else if AE = "B" & KeepSwitch = 1 then KeepSwitch = 0;
	else if AE = "B" & KeepSwitch = 0 then KeepSwitch = 1;
run;

data SetVar;
	set SetSwitch;

	if KeepSwitch = 1 then if AE = " " then AE = lag(AE);
run;

data Want;
	set SetVar;

	if AE ^= " " then output;
run;

View solution in original post

2 REPLIES 2
TomKari
Onyx | Level 15

Untested; when you post a question like this, you should provide your test data in the form of a data step, so I can recreate it to try the program;

 

Tom

 

data SetSwitch;
	retain KeepSwitch 0;
	set Have;

	if AE = "A" then KeepSwitch = 1;
	else if AE = "E" then KeepSwitch = 0;
	else if AE = "B" & KeepSwitch = 1 then KeepSwitch = 0;
	else if AE = "B" & KeepSwitch = 0 then KeepSwitch = 1;
run;

data SetVar;
	set SetSwitch;

	if KeepSwitch = 1 then if AE = " " then AE = lag(AE);
run;

data Want;
	set SetVar;

	if AE ^= " " then output;
run;
MirLuie
Calcite | Level 5
thank you sooo much! you made my day!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1931 views
  • 0 likes
  • 2 in conversation