Solved
Contributor
Posts: 59

# Regarding concatenate

Dear All,

I have a question regarding concatenating the household id and member id for my own research data.

that data looks like this

 Household_ID Member_ID IAP13B0291 5 IAP13B0291 209 IAP13B0293 4ca IAP13B0293 10 IAP13B0293 201 IAP13B0293 204 IAP13B0293 2 IAP13B0293 9 IAP13B0294 8

if i will merge both i need to add 2 zeroes  in front of 5 in 1st observation and 2nd observation i dont want to add please suggest me which function i have to use????

thanks

Anil

Accepted Solutions
Solution
‎01-06-2015 05:16 AM
Super User
Posts: 10,023

## Re: Regarding concatenate

```data have;
input Household_ID : \$20.     Member_ID \$;
cards;
IAP13B0291     5
IAP13B0291     209
IAP13B0293     4ca
IAP13B0293     10
IAP13B0293     201
IAP13B0293     204
IAP13B0293     2
IAP13B0293     9
IAP13B0294     8
;
run;
data want;
set have;
length new \$ 3;
new=Member_ID;
new=translate(right(new),'0',' ');
run;
```

Xia Keshan

All Replies
Posts: 1,228

## Re: Regarding concatenate

If I understood this correctly then this can provide the desired output.

data want;

set have;

if _n_<3 then new_id=cats(Household_ID,'00',Member_ID);

else new_id=cats(Household_ID,Member_ID);

run;

Super User
Posts: 7,942

## Re: Regarding concatenate

It looks to me as if at least one record has only two characters that "00" cat to would not solve (10).  I would suggest a padding algorithm, principally as the id is alpha-numeric (if it was numeric you could use z. format).

data have;
length household_id member_id \$200;
Household_ID="IAP13B0291";  Member_ID="5"; output;
Household_ID="IAP13B0291";  Member_ID="209"; output;
Household_ID="IAP13B0293";  Member_ID="4ca"; output;
run;

data want;
set have;
if length(strip(member_id))=3 then household_id=cats(household_id,member_id);
else household_id=cats(household_id,repeat('0',2-length(strip(member_id))),strip(member_id));
run;

Solution
‎01-06-2015 05:16 AM
Super User
Posts: 10,023

## Re: Regarding concatenate

```data have;
input Household_ID : \$20.     Member_ID \$;
cards;
IAP13B0291     5
IAP13B0291     209
IAP13B0293     4ca
IAP13B0293     10
IAP13B0293     201
IAP13B0293     204
IAP13B0293     2
IAP13B0293     9
IAP13B0294     8
;
run;
data want;
set have;
length new \$ 3;
new=Member_ID;
new=translate(right(new),'0',' ');
run;
```

Xia Keshan

Contributor
Posts: 59

## Re: Regarding   concatenate

Hi Xia Keshan,

It is correct method thank for the help...

thank you all for your suggestions..

Regards,

Anil

Super User
Posts: 19,780