Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Regarding concatenate

Accepted Solution Solved
Reply
Contributor
Posts: 59
Accepted Solution

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_IDMember_ID
IAP13B02915
IAP13B0291209
IAP13B02934ca
IAP13B029310
IAP13B0293201
IAP13B0293204
IAP13B02932
IAP13B02939
IAP13B02948

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

Posted in reply to anilgvdbm
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

View solution in original post


All Replies
Trusted Advisor
Posts: 1,228

Re: Regarding concatenate

Posted in reply to anilgvdbm

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
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

Posted in reply to anilgvdbm
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

Re: Regarding   concatenate

Posted in reply to anilgvdbm

Please mark as answered Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 366 views
  • 1 like
  • 5 in conversation