BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
willy06251
Fluorite | Level 6

Hi SAS experts

 

I would like to know how to manipulate the below data where the

distinct_id is numeric

prog is string

client_id is string

DISTINCT_ID prog CLIENT_ID
0 H 1101,1102
1 C 1110
1 D 1150
1 H 1170,1175,1154

 

 

so that I end up with below where client_id is now numeric

DISTINCT_ID prog CLIENT_ID
0 H 1101
0 H 1102
1 C 1101
1 D 1150
1 H 1170
1 H 1175
1 H 1154

 

So basically, upgrouping the datasets and deriving the transaction dataset.

I am aware that you normally go the other way around so I am finding this tricky.

 

How do you achieve this?

 

Thanks so much in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
slchen
Lapis Lazuli | Level 10

data have;
input DISTINCT_ID prog $ CLIENT_ID $20.;
cards;
0 H 1101,1102
1 C 1110
1 D 1150
1 H 1170,1175,1154
;

data want(rename=(var=client_id));
set have;
do i=1 by 0;
var=scan(client_id,i);
if missing(var) then return;
i+1;
output;
end;
drop i client_id;
run;

View solution in original post

3 REPLIES 3
slchen
Lapis Lazuli | Level 10

data have;
input DISTINCT_ID prog $ CLIENT_ID $20.;
cards;
0 H 1101,1102
1 C 1110
1 D 1150
1 H 1170,1175,1154
;

data want(rename=(var=client_id));
set have;
do i=1 by 0;
var=scan(client_id,i);
if missing(var) then return;
i+1;
output;
end;
drop i client_id;
run;

willy06251
Fluorite | Level 6

Thank you so much! I appreciate your time 🙂

PGStats
Opal | Level 21

Keeping it simple:

 

data want;
set have;
do i = 1 to countw(client_id);
    id = input(scan(client_id, i), best.);
    output;
    end;
drop client_id i;
rename id=client_id;
run;

 

 

PG

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