BookmarkSubscribeRSS Feed
gobejo
Calcite | Level 5

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;

4 REPLIES 4
Steelers_In_DC
Barite | Level 11

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

gobejo
Calcite | Level 5

Thank you for the isea Mark. But, i was wondering why i do not see SBB in DATA Want

ballardw
Super User

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.

Steelers_In_DC
Barite | Level 11

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. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1230 views
  • 0 likes
  • 3 in conversation