BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rajeshganta
Calcite | Level 5
How to write a program to repeat a value if x=rajesh for 2 timesthen it has to present as rajesh rajesh
1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

@Rajeshganta wrote:
Thank you it solved my requirement

Then please set the most helpful post as solution.

View solution in original post

7 REPLIES 7
Patrick
Opal | Level 21

@Rajeshganta wrote:
How to write a program to repeat a value if x=rajesh for 2 timesthen it has to present as rajesh rajesh
data sample;
  have='rajesh';
  want=repeat(trim(have)||' ',1);
  output;
run;

proc print data=sample;
run;
Rajeshganta
Calcite | Level 5
Thank you for the solution but i am getting as rajesh rajesh but i want as rajesh
Rajesh in different rows can you please suggest me
andreas_lds
Jade | Level 19

Without posting any sample data (in usable form) answering question is almost always guesswork. From your initial post i would have answered the very same that @Patrick did. If you want to duplicate observations, you have to use the output-statement.

 

data want;
  set have;
  if x = 'rajesh' then output;
  output;
run;
Rajeshganta
Calcite | Level 5
As per my requirement i want name mentioned in nunber of times in different cells as, if i want rajesh as 2 times
Rajesh
Rajesh
gamotte
Rhodochrosite | Level 12

Please give an example of your input dataset and what the output should look like.

 

Does this answer your question ?

 

data have;
input name $ times;
cards;
Rajesh 2
Howard 3
;
run;

data want;
set have;
do i=1 to times;
output;
end;

keep name;
run;
Rajeshganta
Calcite | Level 5
Thank you it solved my requirement
andreas_lds
Jade | Level 19

@Rajeshganta wrote:
Thank you it solved my requirement

Then please set the most helpful post as solution.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 7 replies
  • 4192 views
  • 1 like
  • 4 in conversation