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
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;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.