Below is an example of what i am trying to achieve.
DATA HAVE;
INFILE DATALINES DSD;
INPUT A $CHAR50.;
DATALINES;
June Summary
Responses
MM Regional Calls
ARIZONA
APPOINTMENTS
Contacts
WM AZ
APPOINTMENTS
Contacts
San Diego
APPOINTMENTS
Contacts
LADT
APPOINTMENTS
Contacts
San Gabriel Valley
APPOINTMENTS
Contacts
Orange County+Ontario
APPOINTMENTS
Contacts
Long Beach
APPOINTMENTS
Contacts
SBB
Arizona
APPOINTMENTS
Contacts
San Diego
APPOINTMENTS
Contacts
Los Angeles
APPOINTMENTS
Contacts
Long Beach
APPOINTMENTS
Contacts
San Jose
APPOINTMENTS
Contacts
;
RUN;
DATA WANT;
INFILE DATALINES DSD DLM="|" TRUNCOVER;
INPUT A :$CHAR30. B :$CHAR3. C :$CHAR30.;
DATALINES;
ARIZONA|MM|ARIZONA
APPOINTMENTS|MM|ARIZONA
Contacts|MM|ARIZONA
WM AZ|MM|WM AZ
APPOINTMENTS|MM|WM AZ
Contacts|MM|WM AZ
San Diego|MM|San Diego
APPOINTMENTS|MM|San Diego
Contacts|MM|San Diego
LADT|MM|LADT
APPOINTMENTS|MM|LADT
Contacts|MM|LADT
San Gabriel Valley|MM|San Gabriel Valley
APPOINTMENTS|MM|San Gabriel Valley
Contacts|MM|San Gabriel Valley
Orange County+Ontario|MM|Orange County+Ontario
APPOINTMENTS|MM|Orange County+Ontario
Contacts|MM|Orange County+Ontario
Long Beach|MM|Long Beach
APPOINTMENTS|MM|Long Beach
Contacts|MM|Long Beach
Arizona|SBB|Arizona
APPOINTMENTS|SBB|Arizona
Contacts|SBB|Arizona
San Diego|SBB|San Diego
APPOINTMENTS|SBB|San Diego
Contacts|SBB|San Diego
Los Angeles|SBB|Los Angeles
APPOINTMENTS|SBB|Los Angeles
Contacts|SBB|Los Angeles
Long Beach|SBB|Long Beach
APPOINTMENTS|SBB|Long Beach
Contacts|SBB|Long Beach
;
RUN;
Pretty crude and specific but here is a solution. Won't work for any broader examples.
data want2(keep=a b c);
set have;
count + 1;
retain c;
b = 'MM';
if a = 'MM Regional Calls' then count = 0;
if count = 4 then count = 1;
if count = 1 then c = a;
if 4<=_N_<=48;
run;
Go Pirates
Thank you for the isea Mark. But, i was wondering why i do not see SBB in DATA Want
Probably because the "rule" for why SBB takes the place of MM in the data is not in any way obvious. Do you have other codes in that role as well? You would have to test each record to see if it is the appropriate code and assign to the retained variable.
No idea, it's in my output. You 'd have to provide your code for any additional help. A little note, you didn't mention that anywhere in your initial post.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: