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
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;
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;
Thanks a lot DBailey the code is working fine.
Much appreciated with the immediate solution
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.