DATA Step, Macro, Functions and more

Make Rows Repeat Based on New Value

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

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: 

ValueDate
A01-Jan-18
B01-Jan-18
C01-Jan-18
A02-Jan-18
B02-Jan-18
C02-Jan-18
A03-Jan-18
B03-Jan-18
C03-Jan-18
A04-Jan-18
B04-Jan-18
C04-Jan-18
A05-Jan-18

 


Accepted Solutions
Solution
2 weeks ago
PROC Star
Posts: 1,296

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;

View solution in original post


All Replies
Solution
2 weeks ago
PROC Star
Posts: 1,296

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: 2

Re: Make Rows Repeat Based on New Value

Posted in reply to novinosrin

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:

 

Value2ValueDate
CA01-Jan-18
DA01-Jan-18
EA01-Jan-18
CB01-Jan-18
DB01-Jan-18
EB01-Jan-18
CC01-Jan-18
DC01-Jan-18
EC01-Jan-18
CA02-Jan-18
DA02-Jan-18
EA02-Jan-18
CB02-Jan-18
DB02-Jan-18
EB02-Jan-18
PROC Star
Posts: 1,296

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,534

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 105 views
  • 1 like
  • 3 in conversation