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 |
… | … |
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;
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;
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 |
… | … | … |
Nest it like this--
data want;
set have;
do value='A','B','C';
do value2='C','D','E';
output;
end;
end;
run;
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;
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!
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.