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

Hi,

I am new to this forum and struggling with this query most of the SAS experts weren't able to provide me a solution yet. Any help will certainly be appreciated.

Ex: Assuming a dataset with only variable - Dummy_records which has data in chunks.

What i would like here is the datasets has to be split in to two and condition is the special observation in them - From the below table

Dataset 1 should have the records John, Joseph, Mark & Antony (pulling the records between CMSTART & CMEND)

Dataset 2 must have records between CISTART &  CIEND (Mike, Amy & Abel)

Dummy_records
CMSTART
John
Joseph
Mark
Antony
CMEND

CISTART

Mike

Amy
Abel
CIEND

Probable approach i could think of -

1. A condtion such as between in SQL which could wokr for text strings (if exists)

2. Insert a flag  to differeniate CM records and CI records.

Please let me know if anymore information is required.

Thanks,

Hari Prasad

1 ACCEPTED SOLUTION

Accepted Solutions
DBailey
Lapis Lazuli | Level 10

data DS1 DS2;

set have;

retain key;

if dummy_record = 'CMSTART' then key='CMSTART';

else if dummy_record='CMEND' then key='';

else if dummy_record='CISTART' the key='CISTART';

else if dummy_record='CIEND' then key='';

else do;

     if key='CMSTART' then output ds1;

     else if key='CISTART' then output ds2;

end;

run;

View solution in original post

2 REPLIES 2
DBailey
Lapis Lazuli | Level 10

data DS1 DS2;

set have;

retain key;

if dummy_record = 'CMSTART' then key='CMSTART';

else if dummy_record='CMEND' then key='';

else if dummy_record='CISTART' the key='CISTART';

else if dummy_record='CIEND' then key='';

else do;

     if key='CMSTART' then output ds1;

     else if key='CISTART' then output ds2;

end;

run;

HariPrasad
Calcite | Level 5

Thanks a lot DBailey the code is working fine.

Much appreciated with the immediate solution

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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