BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
shankvi8
Calcite | Level 5

Dear All,

 

Need help in generating repeated sequence. I have 3 inputs in macro variable 

Min Value = 1 (Starting number of the sequence)

Max Value = 3 (Ending number of the sequence)

No of iterations = 2 (No of times the sequence to be repeated)

With the above input I would like to see a dataset with the below result.

1

2

3

1

2

3

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@shankvi8 wrote:

Dear All,

 

Need help in generating repeated sequence. I have 3 inputs in macro variable 

Min Value = 1 (Starting number of the sequence)

Max Value = 3 (Ending number of the sequence)

No of iterations = 2 (No of times the sequence to be repeated)

With the above input I would like to see a dataset with the below result.

1

2

3

1

2

3


You could at least provide the names of your macro variables, the name of the data set and variable in the dataset.

One way:

%let min= 1;
%let max= 3;
%let iter= 2;

data want;
   do i= 1 to &iter;
      do x=&min to &max;
         output;
      end;
   end;
   drop i;
run;

Caution: this makes to checks that max is greater than min.

View solution in original post

3 REPLIES 3
ballardw
Super User

@shankvi8 wrote:

Dear All,

 

Need help in generating repeated sequence. I have 3 inputs in macro variable 

Min Value = 1 (Starting number of the sequence)

Max Value = 3 (Ending number of the sequence)

No of iterations = 2 (No of times the sequence to be repeated)

With the above input I would like to see a dataset with the below result.

1

2

3

1

2

3


You could at least provide the names of your macro variables, the name of the data set and variable in the dataset.

One way:

%let min= 1;
%let max= 3;
%let iter= 2;

data want;
   do i= 1 to &iter;
      do x=&min to &max;
         output;
      end;
   end;
   drop i;
run;

Caution: this makes to checks that max is greater than min.

PaigeMiller
Diamond | Level 26
data want;
    do j=1 to &no_of_iterations;
        do i=&minvalue to &maxvalue;
            output;
        end;
    drop j;
run;
--
Paige Miller
shankvi8
Calcite | Level 5
Excellent. Thanks for sharing

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 841 views
  • 1 like
  • 3 in conversation