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

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 699 views
  • 1 like
  • 3 in conversation