MuI need to create 3 data sets from the below raw data.
COL1 COL2 COL3 COL4
111 111 DDD EEE
222 111 RRR TTT
BAT 23
124 158 FFF FFF
444 454 MMM MMM
BAT 26
555 121 LLL TTT
122 158 JJJ MMM
BAT 33
My first data set should be as follows
COL1 COL2 COL3 COL4
111 111 DDD EEE
222 111 RRR TTT
BAT 23
My second data set should be as follows
COL1 COL2 COL3 COL4
124 158 FFF FFF
444 454 MMM MMM
BAT 26
My third data set should be as follows
COL1 COL2 COL3 COL4
555 121 LLL TTT
122 158 JJJ MMM
BAT 33
So the data set seperator here is the word BAT. I need to create data set of such records that are above the word BAT.
Hi,
Hash() seems to have an edge in term of dynamic outputting dataset:
data _null_;
length col1-col4 $8.;
if _n_=1 then do;
dcl hash h(ordered :'a');
h.definekey('n');
h.definedata('col1', 'col2', 'col3', 'col4');
h.definedone();
end;
do until (col1='BAT');
infile cards truncover;
input (COL1 COL2 COL3 COL4) (:$8.);
n+1;
h.add();
end;
flag+1;
h.output(dataset: 'w'||strip(put(flag,best.)));
h.clear();
cards;
111 111 DDD EEE
222 111 RRR TTT
BAT 23
124 158 FFF FFF
444 454 MMM MMM
BAT 26
555 121 LLL TTT
122 158 JJJ MMM
BAT 33
;
Regards,
Haikuo
Edit: you need to replace 'cards' with your physical file name or reference.
Hi,
Hash() seems to have an edge in term of dynamic outputting dataset:
data _null_;
length col1-col4 $8.;
if _n_=1 then do;
dcl hash h(ordered :'a');
h.definekey('n');
h.definedata('col1', 'col2', 'col3', 'col4');
h.definedone();
end;
do until (col1='BAT');
infile cards truncover;
input (COL1 COL2 COL3 COL4) (:$8.);
n+1;
h.add();
end;
flag+1;
h.output(dataset: 'w'||strip(put(flag,best.)));
h.clear();
cards;
111 111 DDD EEE
222 111 RRR TTT
BAT 23
124 158 FFF FFF
444 454 MMM MMM
BAT 26
555 121 LLL TTT
122 158 JJJ MMM
BAT 33
;
Regards,
Haikuo
Edit: you need to replace 'cards' with your physical file name or reference.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.