BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
boshmers
Calcite | Level 5

Hello, this is my first post here. Thank you in advance for your help

 

So I have this datset where id_client is the identifier for my clients, n_try is the numer of times i've tryed to contact them for a purchase proposal anche outcome is Y for "accepted", N is "did not accept" and O is for "did not answered the phone"

 

id_clientn_tryoutcome
211O
212N
531O
532O
533Y
171Y
172Y
173N
174O

 

I want to obtain the outcome

id_clientn_tryoutcomepattern
211OO
212NON
531OO
532OOO
533YOOY
171YY
172YYY
173NYYN
174OYYNO

 

Can you help me?

 

Thank you!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello @boshmers ,

 

Welcome to the SAS Communities!

 

Here's AN answer to your question (it's not THE answer as there are always many alternatives to achieve the same).

 

I don't know if it's important to restore the original sort order of the clients. If so, just let me know ... then we fix that too !

 

data have0;
input id_client	n_try outcome $;
datalines;
21 1 O
21 2 N
53 1 O
53 2 O
53 3 Y
17 1 Y
17 2 Y
17 3 N
17 4 O
; 

PROC SORT data=have0 out=have1;
 by id_client n_try;
run;

data want;
 LENGTH pattern $ 50;
 set have1;
 retain pattern;
 by id_client;
 if first.id_client then pattern="";
 pattern=strip(pattern) !! ' ' !! strip(outcome);
run;

proc print; run;
/* end of program */

BR,

Koen

View solution in original post

3 REPLIES 3
sbxkoenk
SAS Super FREQ

Hello @boshmers ,

 

Welcome to the SAS Communities!

 

Here's AN answer to your question (it's not THE answer as there are always many alternatives to achieve the same).

 

I don't know if it's important to restore the original sort order of the clients. If so, just let me know ... then we fix that too !

 

data have0;
input id_client	n_try outcome $;
datalines;
21 1 O
21 2 N
53 1 O
53 2 O
53 3 Y
17 1 Y
17 2 Y
17 3 N
17 4 O
; 

PROC SORT data=have0 out=have1;
 by id_client n_try;
run;

data want;
 LENGTH pattern $ 50;
 set have1;
 retain pattern;
 by id_client;
 if first.id_client then pattern="";
 pattern=strip(pattern) !! ' ' !! strip(outcome);
run;

proc print; run;
/* end of program */

BR,

Koen

boshmers
Calcite | Level 5

Thank you, it worked perfectly!

PaigeMiller
Diamond | Level 26

As this is your first post here, please understand that I give this advice to lots of people. Transforming data for distinct outcomes in each row, to something like ON when there are two outcomes, is often a mistake and actually makes further analysis more difficult. I would advise you to leave the data un-transformed, and explain what you are going to do with it, so we can determine good ways to perform the next steps and whether or not this transformation is helpful.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 505 views
  • 1 like
  • 3 in conversation