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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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