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!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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