Solved
New Contributor
Posts: 4

Make Rows Repeat Based on New Value

I have

 Date 01-Jan-18 02-Jan-18 03-Jan-18 04-Jan-18 05-Jan-18 06-Jan-18 07-Jan-18 08-Jan-18 09-Jan-18 10-Jan-18

I want to repeat the above dates for some new values A,B,C.

So I want:

 Value Date A 01-Jan-18 B 01-Jan-18 C 01-Jan-18 A 02-Jan-18 B 02-Jan-18 C 02-Jan-18 A 03-Jan-18 B 03-Jan-18 C 03-Jan-18 A 04-Jan-18 B 04-Jan-18 C 04-Jan-18 A 05-Jan-18 … …

Accepted Solutions
Solution
‎05-09-2018 11:18 AM
Super User
Posts: 2,049

Re: Make Rows Repeat Based on New Value

``````
data have;
input Date :date9.;
format Date date9.;
cards;
01-Jan-18
02-Jan-18
03-Jan-18
04-Jan-18
05-Jan-18
06-Jan-18
07-Jan-18
08-Jan-18
09-Jan-18
10-Jan-18
;

data want;
set have;
do value='A','B','C';
output;
end;
run;``````

All Replies
Solution
‎05-09-2018 11:18 AM
Super User
Posts: 2,049

Re: Make Rows Repeat Based on New Value

``````
data have;
input Date :date9.;
format Date date9.;
cards;
01-Jan-18
02-Jan-18
03-Jan-18
04-Jan-18
05-Jan-18
06-Jan-18
07-Jan-18
08-Jan-18
09-Jan-18
10-Jan-18
;

data want;
set have;
do value='A','B','C';
output;
end;
run;``````
New Contributor
Posts: 4

Re: Make Rows Repeat Based on New Value

Thanks so much. What if I have another new set of values (C,D,E). Can I fit both into one code? or Do I have to do it twice? So I want:

 Value2 Value Date C A 01-Jan-18 D A 01-Jan-18 E A 01-Jan-18 C B 01-Jan-18 D B 01-Jan-18 E B 01-Jan-18 C C 01-Jan-18 D C 01-Jan-18 E C 01-Jan-18 C A 02-Jan-18 D A 02-Jan-18 E A 02-Jan-18 C B 02-Jan-18 D B 02-Jan-18 E B 02-Jan-18 … … …
Super User
Posts: 2,049

Re: Make Rows Repeat Based on New Value

Nest it like this--

``````data want;
set have;
do value='A','B','C';
do value2='C','D','E';
output;
end;
end;
run;``````
Super User
Posts: 6,921

Re: Make Rows Repeat Based on New Value

If your list of values (A, B, C) is long, it might be more practical to store them in a data set and use SQL:

proc sql;

create table want as select * from date_table, value_table

order by date value;

quit;

☑ This topic is solved.