New Contributor
Posts: 3

# Group by, index and concatenate

Need help with doing the following... dont know where to start or how to do it! :smileyconfused:

seems pretty hard to do!

Super User
Posts: 9,599

## Re: Group by, index and concatenate

Hi,

data want;

set have;

retain artname2 artedit_id;

if substr(art_name,1,1) ne "2" then do;

artname2=art_name;

artedit_id=art_name;

end;

Run;

New Contributor
Posts: 3

## Re: Group by, index and concatenate

They there RW9,

this was very helpful, and much easier than I thought.

just 2 questions;

1. can you explain to me : if substr(art_name,1,1) ne "2" then do;

2. in artedit_id=art_name; how does one concatenate 2 different data types - a character and number, does a copy of version need to be created as a character and then concatenated with art_name_2?

thanking you & regards,

m.

New Contributor
Posts: 3

## Re: Group by, index and concatenate

hello RW9,

following on from my post below.

i got this done.

i did it over a number of data steps, but its okay i guess, it got the job done

data test;

set sample_wiki7;

retain artname2 artedit_id;

if substr(art_name,1,1) ne "2" then do;

artname2=art_name;

end;

run;

data test2;

set test;

version2 = put(version, 3.) ;

run;

data test3;

set test2;

ID = catx('', artname2,version2) ;

run;

Super User
Posts: 9,599

## Re: Group by, index and concatenate

Hi,

1)  It basically means if the first character of art_name is a 2, so it s not one we hold over the next rows, then retain that value.

2)  To concatenate different types, there is several options.  The main one would be put (and input) which convert data.  So string || put(number,best.)  will transform the number into a string defined by the format - best. in this case) - and then concatenate that string to the other.

Glad you got your job done, you can wrap up the code lines as:

data test;

set sample_wiki7;

retain artname2 artedit_id;

if substr(art_name,1,1) ne "2" then do;

artname2=art_name;

end;

version2 = put(version, 3.) ;

ID = catx('', artname2,version2) ;

run;

Discussion stats
• 4 replies
• 225 views
• 1 like
• 2 in conversation