BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
oliviameng
Calcite | Level 5

Hi,

 

I'm writting a loop to create a new table as following and got stacked. 

Here is an example table with a table of scores for different months. There are date_1 and Date_2(table #1).

I need to create a new table(table #2) to only keep the scores from date_1 to date_2, and in line with date_2(as Mon_0).

Is there a way to write a do loop/array to solve the problem? Really appreciate.

 

Table #1

IDdate_1date_2sc_201501sc_201502sc_201503sc_201504sc_201505sc_201506sc_201507sc_201508sc_201509sc_201510sc_201511sc_201512sc_201601sc_201602sc_201603sc_201604sc_201605sc_201606sc_201607sc_201608sc_201609sc_201610sc_201611sc_201612
12015_012016_020.6580.8880.3300.9380.1480.0620.5980.9440.7700.1890.1440.8420.3720.4810.1230.6300.2760.2920.6260.6650.8850.6140.3310.467
22016_012016_120.4140.9150.7480.1600.3880.1000.7510.0890.7860.1260.3050.8520.8740.8750.4140.4040.2680.7300.7600.4430.5770.2310.6410.398
32016_042016_120.6140.1660.4650.3470.6800.0420.4000.9590.2230.6030.9180.9540.2890.4800.6260.6380.4510.4780.1970.1750.0930.0960.5350.990
42016_032016_110.0540.8710.0870.2860.8010.7010.6170.0150.2150.5460.4670.2190.5610.3970.8780.4810.4180.8870.7580.5750.7500.3640.8980.437
52015_122016_050.8880.4530.6490.6170.7340.2440.5120.0330.9640.4160.7390.1830.6650.5880.9620.7550.5000.2360.9830.8430.2560.4890.3940.682
62015_102016_030.5170.4930.2390.9600.0500.0820.7010.5760.8920.4460.1670.4670.0850.0470.4920.8370.2890.1070.8400.4420.9510.7850.1690.173
72015_022015_120.2060.5870.5180.2330.9060.9830.2730.8450.6000.5140.9200.1820.4330.0260.9480.2810.3470.2720.8180.0540.4150.7590.5470.319

 

Table #2

IDdate_1date_2Mon_before14Mon_before13Mon_before12Mon_before11Mon_before10Mon_before9Mon_before8Mon_before7Mon_before6Mon_before5Mon_before4Mon_before3Mon_before2Mon_before1Mon_0
12015_012016_02 0.6580.8880.3300.9380.1480.0620.5980.9440.7700.1890.1440.8420.3720.481
22016_012016_12   0.8740.8750.4140.4040.2680.7300.7600.4430.5770.2310.6410.398
32016_042016_12      0.6380.4510.4780.1970.1750.0930.0960.5350.990
42016_032016_11      0.8780.4810.4180.8870.7580.5750.7500.3640.898
52015_122016_05         0.1830.6650.5880.9620.7550.500
62015_102016_03         0.4460.1670.4670.0850.0470.492
72015_022015_12    0.5870.5180.2330.9060.9830.2730.8450.6000.5140.9200.182

 

Many thanks,

Olivia
 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Transpose to a long format, then set the "month before" variable with intck(), or delete if it's before date_1 or after date_2.

If you still need the horizontal format in the output, transpose back.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Transpose to a long format, then set the "month before" variable with intck(), or delete if it's before date_1 or after date_2.

If you still need the horizontal format in the output, transpose back.

oliviameng
Calcite | Level 5

Thank you. This is much easier way than writing a loop and with arrays.

 

Olivia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 849 views
  • 0 likes
  • 2 in conversation