Help using Base SAS procedures

Splitting datasets using the records in datasets as condition?

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Splitting datasets using the records in datasets as condition?

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


Accepted Solutions
Solution
‎04-24-2013 10:34 AM
Super Contributor
Posts: 578

Re: Splitting datasets using the records in datasets as condition?

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


All Replies
Solution
‎04-24-2013 10:34 AM
Super Contributor
Posts: 578

Re: Splitting datasets using the records in datasets as condition?

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;

New Contributor
Posts: 3

Re: Splitting datasets using the records in datasets as condition?

Thanks a lot DBailey the code is working fine.

Much appreciated with the immediate solution

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 181 views
  • 2 likes
  • 2 in conversation