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-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 971 views
  • 0 likes
  • 3 in conversation