data.flu10

Obs Date usa California Florida Texas
1 2013-10-06 1405 1549 1474 2052
2 2013-10-13 1354 1506 1490 1955
3 2013-10-20 1445 1624 1457 2206
4 2013-10-27 1460 1682 1569 2301



data.flu9

Obs Date usa California Florida Texas
1 2013-09-01 1085 1241 997 1589
2 2013-09-08 1154 1310 1137 1657
3 2013-09-15 1259 1407 1060 1857
4 2013-09-22 1350 1490 1157 2041
5 2013-09-29 1363 1514 1250 2024



data.append: append set

Obs Date usa California Florida Texas
1 2013-10-06 1405 1549 1474 2052
2 2013-10-13 1354 1506 1490 1955
3 2013-10-20 1445 1624 1457 2206
4 2013-10-27 1460 1682 1569 2301
5 2013-09-01 1085 1241 997 1589
6 2013-09-08 1154 1310 1137 1657
7 2013-09-15 1259 1407 1060 1857
8 2013-09-22 1350 1490 1157 2041
9 2013-09-29 1363 1514 1250 2024



flu10: proc append

Obs Date usa California Florida Texas
1 2013-10-06 1405 1549 1474 2052
2 2013-10-13 1354 1506 1490 1955
3 2013-10-20 1445 1624 1457 2206
4 2013-10-27 1460 1682 1569 2301
5 2013-09-01 1085 1241 997 1589
6 2013-09-08 1154 1310 1137 1657
7 2013-09-15 1259 1407 1060 1857
8 2013-09-22 1350 1490 1157 2041
9 2013-09-29 1363 1514 1250 2024



Obs Date usa California Florida Texas
1 2013-10-06 1405 1549 1474 2052
2 2013-10-13 1354 1506 1490 1955
3 2013-10-20 1445 1624 1457 2206
4 2013-10-27 1460 1682 1569 2301



Obs Date usa Kansas Oklahoma Texas
1 2013-09-01 1085 322 1712 1589
2 2013-09-08 1154 558 2058 1657
3 2013-09-15 1259 647 2165 1857
4 2013-09-22 1350 962 2542 2041
5 2013-09-29 1363 971 2141 2024



data.append2: add more rows for diff columns

Obs Date usa California Florida Texas Kansas Oklahoma month
1 2013-10-06 1405 1549 1474 2052 . . Oct
2 2013-10-13 1354 1506 1490 1955 . . Oct
3 2013-10-20 1445 1624 1457 2206 . . Oct
4 2013-10-27 1460 1682 1569 2301 . . Oct
5 2013-09-01 1085 . . 1589 322 1712 Sep
6 2013-09-08 1154 . . 1657 558 2058 Sep
7 2013-09-15 1259 . . 1857 647 2165 Sep
8 2013-09-22 1350 . . 2041 962 2542 Sep
9 2013-09-29 1363 . . 2024 971 2141 Sep



Obs Date usa California Florida Texas
1 2013-10-06 1405 1549 1474 2052
2 2013-10-13 1354 1506 1490 1955
3 2013-10-20 1445 1624 1457 2206
4 2013-10-27 1460 1682 1569 2301



Obs Date Kansas Oklahoma
1 2013-09-01 322 1712
2 2013-09-08 558 2058
3 2013-09-15 647 2165
4 2013-10-06 604 2911
5 2013-10-13 527 2588



data.addcol: add more columns, matching up (1-to-1) rows by key(=date) no shared col

Obs Date usa California Florida Texas Kansas Oklahoma
1 2013-09-01 . . . . 322 1712
2 2013-09-08 . . . . 558 2058
3 2013-09-15 . . . . 647 2165
4 2013-10-06 1405 1549 1474 2052 604 2911
5 2013-10-13 1354 1506 1490 1955 527 2588
6 2013-10-20 1445 1624 1457 2206 . .
7 2013-10-27 1460 1682 1569 2301 . .



Obs Date usa California Florida Texas
1 2013-10-06 1405 1549 1474 2052
2 2013-10-13 1354 1506 1490 1955
3 2013-10-20 1445 1624 1457 2206
4 2013-10-27 1460 1682 1569 2301



Obs Date usa Kansas Oklahoma
1 2013-09-01 100 322 1712
2 2013-09-08 100 558 2058
3 2013-09-15 100 647 2165
4 2013-10-06 100 604 2911
5 2013-10-13 100 527 2588



Obs Date usa Kansas Oklahoma qtr
1 2013-09-01 1085 322 1712 3
2 2013-09-08 1154 558 2058 3
3 2013-09-15 1259 647 2165 3
4 2013-10-06 1405 604 2911 4
5 2013-10-13 1354 527 2588 4



Obs qtr quarter
1 1 First_Qtr
2 2 Second_Qtr
3 3 Third_Qtr
4 4 Fourth_Qtr



data.addcol3: add more columns, matching up (1-to-N) rows by key(=qtr) no shared col

Obs qtr quarter Date usa Kansas Oklahoma
1 3 Third_Qtr 2013-09-01 1085 322 1712
2 3 Third_Qtr 2013-09-08 1154 558 2058
3 3 Third_Qtr 2013-09-15 1259 647 2165
4 4 Fourth_Qtr 2013-10-06 1405 604 2911
5 4 Fourth_Qtr 2013-10-13 1354 527 2588



Obs Date usa Kansas Oklahoma qtr
1 2013-09-01 1085 322 1712 3
2 2013-09-08 1154 558 2058 3
3 2013-09-15 1259 647 2165 3
4 2013-10-06 1405 604 2911 4
5 2013-10-13 1354 527 2588 4



Obs qtr quarter
1 1 First_Qtr
2 2 Second_Qtr
3 3 Third_Qtr
4 3 3rd_Qtr
5 4 Fourth_Qtr



dd more columns, matching up (N-to-N) rows by key(=qtr) no shared col: DO NOT use merge. Use proc sql

Obs qtr quarter Date usa Kansas Oklahoma
1 3 Third_Qtr 2013-09-01 1085 322 1712
2 3 3rd_Qtr 2013-09-08 1154 558 2058
3 3 3rd_Qtr 2013-09-15 1259 647 2165
4 4 Fourth_Qtr 2013-10-06 1405 604 2911
5 4 Fourth_Qtr 2013-10-13 1354 527 2588



Obs Date usa California Florida Texas yyyymm
1 2013-09-01 1085 1241 997 1589 201309
2 2013-09-08 1154 1310 1137 1657 201309
3 2013-09-15 1259 1407 1060 1857 201309
4 2013-09-22 1350 1490 1157 2041 201309
5 2013-09-29 1363 1514 1250 2024 201309
6 2013-10-06 1405 1549 1474 2052 201310
7 2013-10-13 1354 1506 1490 1955 201310
8 2013-10-20 1445 1624 1457 2206 201310
9 2013-10-27 1460 1682 1569 2301 201310



combine rows by key(=yyyymm): sum

Obs yyyymm _TYPE_ _FREQ_ usa California Florida Texas max_usa
1 201309 0 5 6211 6962 5601 9168 1363
2 201310 0 4 5664 6361 5990 8514 1460



combine rows by key(=yyyymm): sum + max USA

Obs yyyymm _TYPE_ _FREQ_ usa California Florida Texas
1 201309 0 5 6211 6962 5601 9168
2 201310 0 4 5664 6361 5990 8514



combine rows by key(=yyyymm): combo

Obs yyyymm nrows sca maxfl mintx stx
1 201309 5 6962 1250 1589 9168
2 201310 4 6361 1569 1955 8514



combine rows by key(=yyyymm): no by statement

Obs _TYPE_ _FREQ_ usa California Florida Texas
1 0 9 11875 13323 11591 17682



Obs Date usa California Florida Texas yyyymm
1 2013-09-01 1085 1241 997 1589 201309
2 2013-09-08 1154 1310 1137 1657 201309
3 2013-09-15 1259 1407 1060 1857 201309
4 2013-09-22 1350 1490 1157 2041 201309
5 2013-09-29 1363 1514 1250 2024 201309
6 2013-10-06 1405 1549 1474 2052 201310
7 2013-10-13 1354 1506 1490 1955 201310
8 2013-10-20 1445 1624 1457 2206 201310
9 2013-10-27 1460 1682 1569 2301 201310



proc transpose data=append out=data.tappend

Obs _NAME_ COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9
1 Date 19602 19609 19616 19623 19630 19637 19644 19651 19658
2 usa 1085 1154 1259 1350 1363 1405 1354 1445 1460
3 California 1241 1310 1407 1490 1514 1549 1506 1624 1682
4 Florida 997 1137 1060 1157 1250 1474 1490 1457 1569
5 Texas 1589 1657 1857 2041 2024 2052 1955 2206 2301
6 yyyymm 201309 201309 201309 201309 201309 201310 201310 201310 201310



proc transpose... id date;

Obs _NAME_ _2013N09N01 _2013N09N08 _2013N09N15 _2013N09N22 _2013N09N29 _2013N10N06 _2013N10N13 _2013N10N20 _2013N10N27
1 usa 1085 1154 1259 1350 1363 1405 1354 1445 1460
2 California 1241 1310 1407 1490 1514 1549 1506 1624 1682
3 Florida 997 1137 1060 1157 1250 1474 1490 1457 1569
4 Texas 1589 1657 1857 2041 2024 2052 1955 2206 2301
5 yyyymm 201309 201309 201309 201309 201309 201310 201310 201310 201310



proc transpose... id date; var ...;

Obs state _2013N09N01 _2013N09N08 _2013N09N15 _2013N09N22 _2013N09N29 _2013N10N06 _2013N10N13 _2013N10N20 _2013N10N27
1 usa 1085 1154 1259 1350 1363 1405 1354 1445 1460
2 California 1241 1310 1407 1490 1514 1549 1506 1624 1682
3 Florida 997 1137 1060 1157 1250 1474 1490 1457 1569
4 Texas 1589 1657 1857 2041 2024 2052 1955 2206 2301



Obs Date usa California Florida Texas yyyymm
1 2013-09-01 1085 1241 997 1589 201309
2 2013-09-08 1154 1310 1137 1657 201309
3 2013-09-15 1259 1407 1060 1857 201309
4 2013-09-22 1350 1490 1157 2041 201309
5 2013-09-29 1363 1514 1250 2024 201309
6 2013-10-06 1405 1549 1474 2052 201310
7 2013-10-13 1354 1506 1490 1955 201310
8 2013-10-20 1445 1624 1457 2206 201310
9 2013-10-27 1460 1682 1569 2301 201310



Obs Date usa California Florida Texas yyyymm
1 2013-09-01 1085 1241 997 1589 201309
2 2013-10-06 1405 1549 1474 2052 201310



proc transpose... id yyyymm: first week

Obs state _201309 _201310
1 usa 1085 1405
2 California 1241 1549
3 Florida 997 1474
4 Texas 1589 2052



Obs Date usa California Florida Texas yyyymm
1 2013-09-01 1085 1241 997 1589 201309
2 2013-09-08 1154 1310 1137 1657 201309
3 2013-09-15 1259 1407 1060 1857 201309
4 2013-09-22 1350 1490 1157 2041 201309
5 2013-09-29 1363 1514 1250 2024 201309
6 2013-10-06 1405 1549 1474 2052 201310
7 2013-10-13 1354 1506 1490 1955 201310
8 2013-10-20 1445 1624 1457 2206 201310
9 2013-10-27 1460 1682 1569 2301 201310



Obs yyyymm _TYPE_ _FREQ_ usa California Florida Texas
1 201309 0 5 6211 6962 5601 9168
2 201310 0 4 5664 6361 5990 8514



proc transpose... id yyyymm : sum

Obs state flu201309 flu201310
1 usa 6211 5664
2 California 6962 6361
3 Florida 5601 5990
4 Texas 9168 8514



proc transpose ... back

Obs _NAME_ usa California Florida Texas
1 flu201309 6211 6962 5601 9168
2 flu201310 5664 6361 5990 8514



proc transpose ... back fully

Obs _NAME_ usa California Florida Texas yyyymm
1 flu201309 6211 6962 5601 9168 201309
2 flu201310 5664 6361 5990 8514 201310



Obs Date usa California Florida Texas yyyymm week
1 2013-09-01 1085 1241 997 1589 201309 wk1
2 2013-09-08 1154 1310 1137 1657 201309 wk2
3 2013-09-15 1259 1407 1060 1857 201309 wk3
4 2013-09-22 1350 1490 1157 2041 201309 wk4
5 2013-09-29 1363 1514 1250 2024 201309 wk5
6 2013-10-06 1405 1549 1474 2052 201310 wk1
7 2013-10-13 1354 1506 1490 1955 201310 wk2
8 2013-10-20 1445 1624 1457 2206 201310 wk3
9 2013-10-27 1460 1682 1569 2301 201310 wk4



proc transpose .. by group

Obs yyyymm state wk1 wk2 wk3 wk4 wk5
1 201309 usa 1085 1154 1259 1350 1363
2 201309 California 1241 1310 1407 1490 1514
3 201309 Florida 997 1137 1060 1157 1250
4 201309 Texas 1589 1657 1857 2041 2024
5 201310 usa 1405 1354 1445 1460 .
6 201310 California 1549 1506 1624 1682 .
7 201310 Florida 1474 1490 1457 1569 .
8 201310 Texas 2052 1955 2206 2301 .



proc transpose .. by group.. back

Obs yyyymm week usa California Florida Texas
1 201309 wk1 1085 1241 997 1589
2 201309 wk2 1154 1310 1137 1657
3 201309 wk3 1259 1407 1060 1857
4 201309 wk4 1350 1490 1157 2041
5 201309 wk5 1363 1514 1250 2024
6 201310 wk1 1405 1549 1474 2052
7 201310 wk2 1354 1506 1490 1955
8 201310 wk3 1445 1624 1457 2206
9 201310 wk4 1460 1682 1569 2301
10 201310 wk5 . . . .



proc transpose .. by group.. back fully

Obs yyyymm week usa California Florida Texas
1 201309 wk1 1085 1241 997 1589
2 201309 wk2 1154 1310 1137 1657
3 201309 wk3 1259 1407 1060 1857
4 201309 wk4 1350 1490 1157 2041
5 201309 wk5 1363 1514 1250 2024
6 201310 wk1 1405 1549 1474 2052
7 201310 wk2 1354 1506 1490 1955
8 201310 wk3 1445 1624 1457 2206
9 201310 wk4 1460 1682 1569 2301