DATA Step, Macro, Functions and more

Duplicating strings in a column

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Duplicating strings in a column

Hi I have a varibale called "Chosen" that is populated with strings, either "Plane" "Auto" or Transit". 

I want to create a new column with the first string in the "Chosen" repeated 3 times, the second string repeated 3 times and so on. 

Thanks in advance 

 


Accepted Solutions
Solution
‎08-26-2016 09:34 AM
Super User
Super User
Posts: 7,997

Re: Duplicating strings in a column

Posted in reply to mattteale

Hi,

 

Its a good idea to post test data, in the form of a datastep and what the output should look like.  Here I am I am guessing what you have/want:

data have;
  chosen="Plane"; output;
  chosen="Auto"; output;
  chosen="Transit"; output;
run;

data want (drop=i);
  set have;
  do i=1 to 3;
    output; 
  end;
run;

View solution in original post


All Replies
Solution
‎08-26-2016 09:34 AM
Super User
Super User
Posts: 7,997

Re: Duplicating strings in a column

Posted in reply to mattteale

Hi,

 

Its a good idea to post test data, in the form of a datastep and what the output should look like.  Here I am I am guessing what you have/want:

data have;
  chosen="Plane"; output;
  chosen="Auto"; output;
  chosen="Transit"; output;
run;

data want (drop=i);
  set have;
  do i=1 to 3;
    output; 
  end;
run;
New Contributor
Posts: 3

Re: Duplicating strings in a column

Thanks will do next time

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 195 views
  • 1 like
  • 2 in conversation