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

Hello,

 

This is my original table:

col
a; b; c
b; b; d
d

 

And I want to convert it to:

colis_ais_bis_cis_d
a; b; c1110
b; b; d0101
d0001

 

Any help would be much appreciated!

Jedrek

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

The straitforward way:

 

data have;
input col &:$20.;
datalines4;
a; b; c
b; b; d
d
;;;;

data list;
set have;
obs = _n_;
value = 1;
do i = 1 to countw(col,";");
    w = strip(scan(col, i, ";"));
    output;
    end;
drop i;
run;

proc sort data=list nodupkey; by obs w; run;

proc transpose data=list out=table(drop=_name_ obs) prefix=is_;
id w;
var value;
by obs col;
run;

proc stdize data=table reponly missing=0 out=want;
var is_:;
run;

image.png

PG

View solution in original post

3 REPLIES 3
Reeza
Super User
Is it just the 4 values? Or does these need to be extended and this is a simplified version of your problem?
PGStats
Opal | Level 21

The straitforward way:

 

data have;
input col &:$20.;
datalines4;
a; b; c
b; b; d
d
;;;;

data list;
set have;
obs = _n_;
value = 1;
do i = 1 to countw(col,";");
    w = strip(scan(col, i, ";"));
    output;
    end;
drop i;
run;

proc sort data=list nodupkey; by obs w; run;

proc transpose data=list out=table(drop=_name_ obs) prefix=is_;
id w;
var value;
by obs col;
run;

proc stdize data=table reponly missing=0 out=want;
var is_:;
run;

image.png

PG
Jedrek369
Fluorite | Level 6

Thank you very much! Have a good day.

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
  • 1389 views
  • 2 likes
  • 3 in conversation