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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 681 views
  • 1 like
  • 4 in conversation