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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 233 views
  • 1 like
  • 3 in conversation