<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to lag a DAILY variable by six MONTHS and populate a new variable with that value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/863128#M340968</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would greatly appreciate any assistance on this matter. I've been scouring the internet for solutions but my issue has multiple steps and sas is rather new to me. I am using SAS 9.4 TS Level 1M7.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is that I need to populate a new numeric variable named 'ME6' with the 'ME_October_t' from the end of the month, six months ago for each 'seccode' which is an ID (I have many different IDs). I used INTNX to calculate that lagged date respective for each 'seccode' and titled it in my dataset, 'date6'. After that, I can't seem to find a solution. I hope someone with far better coding skills can assist me! I'm at my wits end!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should look like the image below. I apologize for not using the actual data. If I did that, the picture would be too long since I have daily data and I need to lag it by six months. I hope you can understand it:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sample Layout.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81242i8A9C6DFC4EEF46AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sample Layout.png" alt="Sample Layout.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So from the last line of my sample dataset below which is for date 19770908, the 'ME6' would be 1425346000 which is the 'ME_October_t' value on 19770331.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the sample dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data WORK.HELP_ANALYSIS;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input data_date:YYMMDDN. seccode:6. ME_October_t:32. date6:YYMMDDN8.;&lt;BR /&gt;format data_date YYMMDDN. seccode 6. date6 YYMMDDN8.;&lt;BR /&gt;datalines;&lt;BR /&gt;19770104 1301 14253460000 19760731&lt;BR /&gt;19770105 1301 14253460000 19760731&lt;BR /&gt;19770106 1301 14253460000 19760731&lt;BR /&gt;19770107 1301 14253460000 19760731&lt;BR /&gt;19770108 1301 14253460000 19760731&lt;BR /&gt;19770110 1301 14253460000 19760731&lt;BR /&gt;19770111 1301 14253460000 19760731&lt;BR /&gt;19770112 1301 14253460000 19760731&lt;BR /&gt;19770113 1301 14253460000 19760731&lt;BR /&gt;19770114 1301 14253460000 19760731&lt;BR /&gt;19770117 1301 14253460000 19760731&lt;BR /&gt;19770118 1301 14253460000 19760731&lt;BR /&gt;19770119 1301 14253460000 19760731&lt;BR /&gt;19770120 1301 14253460000 19760731&lt;BR /&gt;19770121 1301 14253460000 19760731&lt;BR /&gt;19770122 1301 14253460000 19760731&lt;BR /&gt;19770124 1301 14253460000 19760731&lt;BR /&gt;19770125 1301 14253460000 19760731&lt;BR /&gt;19770126 1301 14253460000 19760731&lt;BR /&gt;19770127 1301 14253460000 19760731&lt;BR /&gt;19770128 1301 14253460000 19760731&lt;BR /&gt;19770129 1301 14253460000 19760731&lt;BR /&gt;19770131 1301 14253460000 19760731&lt;BR /&gt;19770201 1301 14253460000 19760831&lt;BR /&gt;19770202 1301 14253460000 19760831&lt;BR /&gt;19770203 1301 14253460000 19760831&lt;BR /&gt;19770204 1301 14253460000 19760831&lt;BR /&gt;19770205 1301 14253460000 19760831&lt;BR /&gt;19770207 1301 14253460000 19760831&lt;BR /&gt;19770208 1301 14253460000 19760831&lt;BR /&gt;19770209 1301 14253460000 19760831&lt;BR /&gt;19770210 1301 14253460000 19760831&lt;BR /&gt;19770212 1301 14253460000 19760831&lt;BR /&gt;19770214 1301 14253460000 19760831&lt;BR /&gt;19770215 1301 14253460000 19760831&lt;BR /&gt;19770216 1301 14253460000 19760831&lt;BR /&gt;19770217 1301 14253460000 19760831&lt;BR /&gt;19770218 1301 14253460000 19760831&lt;BR /&gt;19770221 1301 14253460000 19760831&lt;BR /&gt;19770222 1301 14253460000 19760831&lt;BR /&gt;19770223 1301 14253460000 19760831&lt;BR /&gt;19770224 1301 14253460000 19760831&lt;BR /&gt;19770225 1301 14253460000 19760831&lt;BR /&gt;19770226 1301 14253460000 19760831&lt;BR /&gt;19770228 1301 14253460000 19760831&lt;BR /&gt;19770301 1301 14253460000 19760930&lt;BR /&gt;19770302 1301 14253460000 19760930&lt;BR /&gt;19770303 1301 14253460000 19760930&lt;BR /&gt;19770304 1301 14253460000 19760930&lt;BR /&gt;19770305 1301 14253460000 19760930&lt;BR /&gt;19770307 1301 14253460000 19760930&lt;BR /&gt;19770308 1301 14253460000 19760930&lt;BR /&gt;19770309 1301 14253460000 19760930&lt;BR /&gt;19770310 1301 14253460000 19760930&lt;BR /&gt;19770311 1301 14253460000 19760930&lt;BR /&gt;19770312 1301 14253460000 19760930&lt;BR /&gt;19770314 1301 14253460000 19760930&lt;BR /&gt;19770315 1301 14253460000 19760930&lt;BR /&gt;19770316 1301 14253460000 19760930&lt;BR /&gt;19770317 1301 14253460000 19760930&lt;BR /&gt;19770318 1301 14253460000 19760930&lt;BR /&gt;19770322 1301 14253460000 19760930&lt;BR /&gt;19770323 1301 14253460000 19760930&lt;BR /&gt;19770324 1301 14253460000 19760930&lt;BR /&gt;19770325 1301 14253460000 19760930&lt;BR /&gt;19770326 1301 14253460000 19760930&lt;BR /&gt;19770328 1301 14253460000 19760930&lt;BR /&gt;19770329 1301 14253460000 19760930&lt;BR /&gt;19770330 1301 14253460000 19760930&lt;BR /&gt;19770331 1301 14253460000 19760930&lt;BR /&gt;19770401 1301 14253460000 19761031&lt;BR /&gt;19770402 1301 14253460000 19761031&lt;BR /&gt;19770404 1301 14253460000 19761031&lt;BR /&gt;19770405 1301 14253460000 19761031&lt;BR /&gt;19770406 1301 14253460000 19761031&lt;BR /&gt;19770407 1301 14253460000 19761031&lt;BR /&gt;19770408 1301 14253460000 19761031&lt;BR /&gt;19770409 1301 14253460000 19761031&lt;BR /&gt;19770411 1301 14253460000 19761031&lt;BR /&gt;19770412 1301 14253460000 19761031&lt;BR /&gt;19770413 1301 14253460000 19761031&lt;BR /&gt;19770414 1301 14253460000 19761031&lt;BR /&gt;19770415 1301 14253460000 19761031&lt;BR /&gt;19770418 1301 14253460000 19761031&lt;BR /&gt;19770419 1301 14253460000 19761031&lt;BR /&gt;19770420 1301 14253460000 19761031&lt;BR /&gt;19770421 1301 14253460000 19761031&lt;BR /&gt;19770422 1301 14253460000 19761031&lt;BR /&gt;19770423 1301 14253460000 19761031&lt;BR /&gt;19770425 1301 14253460000 19761031&lt;BR /&gt;19770426 1301 14253460000 19761031&lt;BR /&gt;19770427 1301 14253460000 19761031&lt;BR /&gt;19770428 1301 14253460000 19761031&lt;BR /&gt;19770430 1301 14253460000 19761031&lt;BR /&gt;19770502 1301 14253460000 19761130&lt;BR /&gt;19770504 1301 14253460000 19761130&lt;BR /&gt;19770506 1301 14253460000 19761130&lt;BR /&gt;19770507 1301 14253460000 19761130&lt;BR /&gt;19770509 1301 14253460000 19761130&lt;BR /&gt;19770510 1301 14253460000 19761130&lt;BR /&gt;19770511 1301 14253460000 19761130&lt;BR /&gt;19770512 1301 14253460000 19761130&lt;BR /&gt;19770513 1301 14253460000 19761130&lt;BR /&gt;19770514 1301 14253460000 19761130&lt;BR /&gt;19770516 1301 14253460000 19761130&lt;BR /&gt;19770517 1301 14253460000 19761130&lt;BR /&gt;19770518 1301 14253460000 19761130&lt;BR /&gt;19770519 1301 14253460000 19761130&lt;BR /&gt;19770520 1301 14253460000 19761130&lt;BR /&gt;19770523 1301 14253460000 19761130&lt;BR /&gt;19770524 1301 14253460000 19761130&lt;BR /&gt;19770525 1301 14253460000 19761130&lt;BR /&gt;19770526 1301 14253460000 19761130&lt;BR /&gt;19770527 1301 14253460000 19761130&lt;BR /&gt;19770528 1301 14253460000 19761130&lt;BR /&gt;19770530 1301 14253460000 19761130&lt;BR /&gt;19770531 1301 14253460000 19761130&lt;BR /&gt;19770601 1301 14253460000 19761231&lt;BR /&gt;19770602 1301 14253460000 19761231&lt;BR /&gt;19770603 1301 14253460000 19761231&lt;BR /&gt;19770604 1301 14253460000 19761231&lt;BR /&gt;19770606 1301 14253460000 19761231&lt;BR /&gt;19770607 1301 14253460000 19761231&lt;BR /&gt;19770608 1301 14253460000 19761231&lt;BR /&gt;19770609 1301 14253460000 19761231&lt;BR /&gt;19770610 1301 14253460000 19761231&lt;BR /&gt;19770611 1301 14253460000 19761231&lt;BR /&gt;19770613 1301 14253460000 19761231&lt;BR /&gt;19770614 1301 14253460000 19761231&lt;BR /&gt;19770615 1301 14253460000 19761231&lt;BR /&gt;19770616 1301 14253460000 19761231&lt;BR /&gt;19770617 1301 14253460000 19761231&lt;BR /&gt;19770620 1301 14253460000 19761231&lt;BR /&gt;19770621 1301 14253460000 19761231&lt;BR /&gt;19770622 1301 14253460000 19761231&lt;BR /&gt;19770623 1301 14253460000 19761231&lt;BR /&gt;19770624 1301 14253460000 19761231&lt;BR /&gt;19770625 1301 14253460000 19761231&lt;BR /&gt;19770627 1301 14253460000 19761231&lt;BR /&gt;19770628 1301 14253460000 19761231&lt;BR /&gt;19770629 1301 14253460000 19761231&lt;BR /&gt;19770630 1301 14253460000 19761231&lt;BR /&gt;19770701 1301 14253460000 19770131&lt;BR /&gt;19770702 1301 14253460000 19770131&lt;BR /&gt;19770704 1301 14253460000 19770131&lt;BR /&gt;19770705 1301 14253460000 19770131&lt;BR /&gt;19770706 1301 14253460000 19770131&lt;BR /&gt;19770707 1301 14253460000 19770131&lt;BR /&gt;19770708 1301 14253460000 19770131&lt;BR /&gt;19770709 1301 14253460000 19770131&lt;BR /&gt;19770711 1301 14253460000 19770131&lt;BR /&gt;19770712 1301 14253460000 19770131&lt;BR /&gt;19770713 1301 14253460000 19770131&lt;BR /&gt;19770714 1301 14253460000 19770131&lt;BR /&gt;19770715 1301 14253460000 19770131&lt;BR /&gt;19770718 1301 14253460000 19770131&lt;BR /&gt;19770719 1301 14253460000 19770131&lt;BR /&gt;19770720 1301 14253460000 19770131&lt;BR /&gt;19770721 1301 14253460000 19770131&lt;BR /&gt;19770722 1301 14253460000 19770131&lt;BR /&gt;19770723 1301 14253460000 19770131&lt;BR /&gt;19770725 1301 14253460000 19770131&lt;BR /&gt;19770726 1301 14253460000 19770131&lt;BR /&gt;19770727 1301 14253460000 19770131&lt;BR /&gt;19770728 1301 14253460000 19770131&lt;BR /&gt;19770729 1301 14253460000 19770131&lt;BR /&gt;19770730 1301 14253460000 19770131&lt;BR /&gt;19770801 1301 14253460000 19770228&lt;BR /&gt;19770802 1301 14253460000 19770228&lt;BR /&gt;19770803 1301 14253460000 19770228&lt;BR /&gt;19770804 1301 14253460000 19770228&lt;BR /&gt;19770805 1301 14253460000 19770228&lt;BR /&gt;19770806 1301 14253460000 19770228&lt;BR /&gt;19770808 1301 14253460000 19770228&lt;BR /&gt;19770809 1301 14253460000 19770228&lt;BR /&gt;19770810 1301 14253460000 19770228&lt;BR /&gt;19770811 1301 14253460000 19770228&lt;BR /&gt;19770812 1301 14253460000 19770228&lt;BR /&gt;19770813 1301 14253460000 19770228&lt;BR /&gt;19770815 1301 14253460000 19770228&lt;BR /&gt;19770816 1301 14253460000 19770228&lt;BR /&gt;19770817 1301 14253460000 19770228&lt;BR /&gt;19770818 1301 14253460000 19770228&lt;BR /&gt;19770819 1301 14253460000 19770228&lt;BR /&gt;19770822 1301 14253460000 19770228&lt;BR /&gt;19770823 1301 14253460000 19770228&lt;BR /&gt;19770824 1301 14253460000 19770228&lt;BR /&gt;19770825 1301 14253460000 19770228&lt;BR /&gt;19770826 1301 14253460000 19770228&lt;BR /&gt;19770827 1301 14253460000 19770228&lt;BR /&gt;19770829 1301 14253460000 19770228&lt;BR /&gt;19770830 1301 14253460000 19770228&lt;BR /&gt;19770831 1301 14253460000 19770228&lt;BR /&gt;19770901 1301 14253460000 19770331&lt;BR /&gt;19770902 1301 14253460000 19770331&lt;BR /&gt;19770903 1301 14253460000 19770331&lt;BR /&gt;19770905 1301 14253460000 19770331&lt;BR /&gt;19770906 1301 14253460000 19770331&lt;BR /&gt;19770907 1301 14253460000 19770331&lt;BR /&gt;19770908 1301 14253460000 19770331&lt;BR /&gt;;;;;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Mar 2023 04:35:33 GMT</pubDate>
    <dc:creator>slee77</dc:creator>
    <dc:date>2023-03-09T04:35:33Z</dc:date>
    <item>
      <title>How to lag a DAILY variable by six MONTHS and populate a new variable with that value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/863128#M340968</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would greatly appreciate any assistance on this matter. I've been scouring the internet for solutions but my issue has multiple steps and sas is rather new to me. I am using SAS 9.4 TS Level 1M7.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is that I need to populate a new numeric variable named 'ME6' with the 'ME_October_t' from the end of the month, six months ago for each 'seccode' which is an ID (I have many different IDs). I used INTNX to calculate that lagged date respective for each 'seccode' and titled it in my dataset, 'date6'. After that, I can't seem to find a solution. I hope someone with far better coding skills can assist me! I'm at my wits end!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should look like the image below. I apologize for not using the actual data. If I did that, the picture would be too long since I have daily data and I need to lag it by six months. I hope you can understand it:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sample Layout.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81242i8A9C6DFC4EEF46AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sample Layout.png" alt="Sample Layout.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So from the last line of my sample dataset below which is for date 19770908, the 'ME6' would be 1425346000 which is the 'ME_October_t' value on 19770331.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the sample dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data WORK.HELP_ANALYSIS;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input data_date:YYMMDDN. seccode:6. ME_October_t:32. date6:YYMMDDN8.;&lt;BR /&gt;format data_date YYMMDDN. seccode 6. date6 YYMMDDN8.;&lt;BR /&gt;datalines;&lt;BR /&gt;19770104 1301 14253460000 19760731&lt;BR /&gt;19770105 1301 14253460000 19760731&lt;BR /&gt;19770106 1301 14253460000 19760731&lt;BR /&gt;19770107 1301 14253460000 19760731&lt;BR /&gt;19770108 1301 14253460000 19760731&lt;BR /&gt;19770110 1301 14253460000 19760731&lt;BR /&gt;19770111 1301 14253460000 19760731&lt;BR /&gt;19770112 1301 14253460000 19760731&lt;BR /&gt;19770113 1301 14253460000 19760731&lt;BR /&gt;19770114 1301 14253460000 19760731&lt;BR /&gt;19770117 1301 14253460000 19760731&lt;BR /&gt;19770118 1301 14253460000 19760731&lt;BR /&gt;19770119 1301 14253460000 19760731&lt;BR /&gt;19770120 1301 14253460000 19760731&lt;BR /&gt;19770121 1301 14253460000 19760731&lt;BR /&gt;19770122 1301 14253460000 19760731&lt;BR /&gt;19770124 1301 14253460000 19760731&lt;BR /&gt;19770125 1301 14253460000 19760731&lt;BR /&gt;19770126 1301 14253460000 19760731&lt;BR /&gt;19770127 1301 14253460000 19760731&lt;BR /&gt;19770128 1301 14253460000 19760731&lt;BR /&gt;19770129 1301 14253460000 19760731&lt;BR /&gt;19770131 1301 14253460000 19760731&lt;BR /&gt;19770201 1301 14253460000 19760831&lt;BR /&gt;19770202 1301 14253460000 19760831&lt;BR /&gt;19770203 1301 14253460000 19760831&lt;BR /&gt;19770204 1301 14253460000 19760831&lt;BR /&gt;19770205 1301 14253460000 19760831&lt;BR /&gt;19770207 1301 14253460000 19760831&lt;BR /&gt;19770208 1301 14253460000 19760831&lt;BR /&gt;19770209 1301 14253460000 19760831&lt;BR /&gt;19770210 1301 14253460000 19760831&lt;BR /&gt;19770212 1301 14253460000 19760831&lt;BR /&gt;19770214 1301 14253460000 19760831&lt;BR /&gt;19770215 1301 14253460000 19760831&lt;BR /&gt;19770216 1301 14253460000 19760831&lt;BR /&gt;19770217 1301 14253460000 19760831&lt;BR /&gt;19770218 1301 14253460000 19760831&lt;BR /&gt;19770221 1301 14253460000 19760831&lt;BR /&gt;19770222 1301 14253460000 19760831&lt;BR /&gt;19770223 1301 14253460000 19760831&lt;BR /&gt;19770224 1301 14253460000 19760831&lt;BR /&gt;19770225 1301 14253460000 19760831&lt;BR /&gt;19770226 1301 14253460000 19760831&lt;BR /&gt;19770228 1301 14253460000 19760831&lt;BR /&gt;19770301 1301 14253460000 19760930&lt;BR /&gt;19770302 1301 14253460000 19760930&lt;BR /&gt;19770303 1301 14253460000 19760930&lt;BR /&gt;19770304 1301 14253460000 19760930&lt;BR /&gt;19770305 1301 14253460000 19760930&lt;BR /&gt;19770307 1301 14253460000 19760930&lt;BR /&gt;19770308 1301 14253460000 19760930&lt;BR /&gt;19770309 1301 14253460000 19760930&lt;BR /&gt;19770310 1301 14253460000 19760930&lt;BR /&gt;19770311 1301 14253460000 19760930&lt;BR /&gt;19770312 1301 14253460000 19760930&lt;BR /&gt;19770314 1301 14253460000 19760930&lt;BR /&gt;19770315 1301 14253460000 19760930&lt;BR /&gt;19770316 1301 14253460000 19760930&lt;BR /&gt;19770317 1301 14253460000 19760930&lt;BR /&gt;19770318 1301 14253460000 19760930&lt;BR /&gt;19770322 1301 14253460000 19760930&lt;BR /&gt;19770323 1301 14253460000 19760930&lt;BR /&gt;19770324 1301 14253460000 19760930&lt;BR /&gt;19770325 1301 14253460000 19760930&lt;BR /&gt;19770326 1301 14253460000 19760930&lt;BR /&gt;19770328 1301 14253460000 19760930&lt;BR /&gt;19770329 1301 14253460000 19760930&lt;BR /&gt;19770330 1301 14253460000 19760930&lt;BR /&gt;19770331 1301 14253460000 19760930&lt;BR /&gt;19770401 1301 14253460000 19761031&lt;BR /&gt;19770402 1301 14253460000 19761031&lt;BR /&gt;19770404 1301 14253460000 19761031&lt;BR /&gt;19770405 1301 14253460000 19761031&lt;BR /&gt;19770406 1301 14253460000 19761031&lt;BR /&gt;19770407 1301 14253460000 19761031&lt;BR /&gt;19770408 1301 14253460000 19761031&lt;BR /&gt;19770409 1301 14253460000 19761031&lt;BR /&gt;19770411 1301 14253460000 19761031&lt;BR /&gt;19770412 1301 14253460000 19761031&lt;BR /&gt;19770413 1301 14253460000 19761031&lt;BR /&gt;19770414 1301 14253460000 19761031&lt;BR /&gt;19770415 1301 14253460000 19761031&lt;BR /&gt;19770418 1301 14253460000 19761031&lt;BR /&gt;19770419 1301 14253460000 19761031&lt;BR /&gt;19770420 1301 14253460000 19761031&lt;BR /&gt;19770421 1301 14253460000 19761031&lt;BR /&gt;19770422 1301 14253460000 19761031&lt;BR /&gt;19770423 1301 14253460000 19761031&lt;BR /&gt;19770425 1301 14253460000 19761031&lt;BR /&gt;19770426 1301 14253460000 19761031&lt;BR /&gt;19770427 1301 14253460000 19761031&lt;BR /&gt;19770428 1301 14253460000 19761031&lt;BR /&gt;19770430 1301 14253460000 19761031&lt;BR /&gt;19770502 1301 14253460000 19761130&lt;BR /&gt;19770504 1301 14253460000 19761130&lt;BR /&gt;19770506 1301 14253460000 19761130&lt;BR /&gt;19770507 1301 14253460000 19761130&lt;BR /&gt;19770509 1301 14253460000 19761130&lt;BR /&gt;19770510 1301 14253460000 19761130&lt;BR /&gt;19770511 1301 14253460000 19761130&lt;BR /&gt;19770512 1301 14253460000 19761130&lt;BR /&gt;19770513 1301 14253460000 19761130&lt;BR /&gt;19770514 1301 14253460000 19761130&lt;BR /&gt;19770516 1301 14253460000 19761130&lt;BR /&gt;19770517 1301 14253460000 19761130&lt;BR /&gt;19770518 1301 14253460000 19761130&lt;BR /&gt;19770519 1301 14253460000 19761130&lt;BR /&gt;19770520 1301 14253460000 19761130&lt;BR /&gt;19770523 1301 14253460000 19761130&lt;BR /&gt;19770524 1301 14253460000 19761130&lt;BR /&gt;19770525 1301 14253460000 19761130&lt;BR /&gt;19770526 1301 14253460000 19761130&lt;BR /&gt;19770527 1301 14253460000 19761130&lt;BR /&gt;19770528 1301 14253460000 19761130&lt;BR /&gt;19770530 1301 14253460000 19761130&lt;BR /&gt;19770531 1301 14253460000 19761130&lt;BR /&gt;19770601 1301 14253460000 19761231&lt;BR /&gt;19770602 1301 14253460000 19761231&lt;BR /&gt;19770603 1301 14253460000 19761231&lt;BR /&gt;19770604 1301 14253460000 19761231&lt;BR /&gt;19770606 1301 14253460000 19761231&lt;BR /&gt;19770607 1301 14253460000 19761231&lt;BR /&gt;19770608 1301 14253460000 19761231&lt;BR /&gt;19770609 1301 14253460000 19761231&lt;BR /&gt;19770610 1301 14253460000 19761231&lt;BR /&gt;19770611 1301 14253460000 19761231&lt;BR /&gt;19770613 1301 14253460000 19761231&lt;BR /&gt;19770614 1301 14253460000 19761231&lt;BR /&gt;19770615 1301 14253460000 19761231&lt;BR /&gt;19770616 1301 14253460000 19761231&lt;BR /&gt;19770617 1301 14253460000 19761231&lt;BR /&gt;19770620 1301 14253460000 19761231&lt;BR /&gt;19770621 1301 14253460000 19761231&lt;BR /&gt;19770622 1301 14253460000 19761231&lt;BR /&gt;19770623 1301 14253460000 19761231&lt;BR /&gt;19770624 1301 14253460000 19761231&lt;BR /&gt;19770625 1301 14253460000 19761231&lt;BR /&gt;19770627 1301 14253460000 19761231&lt;BR /&gt;19770628 1301 14253460000 19761231&lt;BR /&gt;19770629 1301 14253460000 19761231&lt;BR /&gt;19770630 1301 14253460000 19761231&lt;BR /&gt;19770701 1301 14253460000 19770131&lt;BR /&gt;19770702 1301 14253460000 19770131&lt;BR /&gt;19770704 1301 14253460000 19770131&lt;BR /&gt;19770705 1301 14253460000 19770131&lt;BR /&gt;19770706 1301 14253460000 19770131&lt;BR /&gt;19770707 1301 14253460000 19770131&lt;BR /&gt;19770708 1301 14253460000 19770131&lt;BR /&gt;19770709 1301 14253460000 19770131&lt;BR /&gt;19770711 1301 14253460000 19770131&lt;BR /&gt;19770712 1301 14253460000 19770131&lt;BR /&gt;19770713 1301 14253460000 19770131&lt;BR /&gt;19770714 1301 14253460000 19770131&lt;BR /&gt;19770715 1301 14253460000 19770131&lt;BR /&gt;19770718 1301 14253460000 19770131&lt;BR /&gt;19770719 1301 14253460000 19770131&lt;BR /&gt;19770720 1301 14253460000 19770131&lt;BR /&gt;19770721 1301 14253460000 19770131&lt;BR /&gt;19770722 1301 14253460000 19770131&lt;BR /&gt;19770723 1301 14253460000 19770131&lt;BR /&gt;19770725 1301 14253460000 19770131&lt;BR /&gt;19770726 1301 14253460000 19770131&lt;BR /&gt;19770727 1301 14253460000 19770131&lt;BR /&gt;19770728 1301 14253460000 19770131&lt;BR /&gt;19770729 1301 14253460000 19770131&lt;BR /&gt;19770730 1301 14253460000 19770131&lt;BR /&gt;19770801 1301 14253460000 19770228&lt;BR /&gt;19770802 1301 14253460000 19770228&lt;BR /&gt;19770803 1301 14253460000 19770228&lt;BR /&gt;19770804 1301 14253460000 19770228&lt;BR /&gt;19770805 1301 14253460000 19770228&lt;BR /&gt;19770806 1301 14253460000 19770228&lt;BR /&gt;19770808 1301 14253460000 19770228&lt;BR /&gt;19770809 1301 14253460000 19770228&lt;BR /&gt;19770810 1301 14253460000 19770228&lt;BR /&gt;19770811 1301 14253460000 19770228&lt;BR /&gt;19770812 1301 14253460000 19770228&lt;BR /&gt;19770813 1301 14253460000 19770228&lt;BR /&gt;19770815 1301 14253460000 19770228&lt;BR /&gt;19770816 1301 14253460000 19770228&lt;BR /&gt;19770817 1301 14253460000 19770228&lt;BR /&gt;19770818 1301 14253460000 19770228&lt;BR /&gt;19770819 1301 14253460000 19770228&lt;BR /&gt;19770822 1301 14253460000 19770228&lt;BR /&gt;19770823 1301 14253460000 19770228&lt;BR /&gt;19770824 1301 14253460000 19770228&lt;BR /&gt;19770825 1301 14253460000 19770228&lt;BR /&gt;19770826 1301 14253460000 19770228&lt;BR /&gt;19770827 1301 14253460000 19770228&lt;BR /&gt;19770829 1301 14253460000 19770228&lt;BR /&gt;19770830 1301 14253460000 19770228&lt;BR /&gt;19770831 1301 14253460000 19770228&lt;BR /&gt;19770901 1301 14253460000 19770331&lt;BR /&gt;19770902 1301 14253460000 19770331&lt;BR /&gt;19770903 1301 14253460000 19770331&lt;BR /&gt;19770905 1301 14253460000 19770331&lt;BR /&gt;19770906 1301 14253460000 19770331&lt;BR /&gt;19770907 1301 14253460000 19770331&lt;BR /&gt;19770908 1301 14253460000 19770331&lt;BR /&gt;;;;;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 04:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/863128#M340968</guid>
      <dc:creator>slee77</dc:creator>
      <dc:date>2023-03-09T04:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag a DAILY variable by six MONTHS and populate a new variable with that value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/864000#M341232</link>
      <description>I cannot read your test data</description>
      <pubDate>Tue, 14 Mar 2023 11:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/864000#M341232</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2023-03-14T11:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag a DAILY variable by six MONTHS and populate a new variable with that value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/864039#M341241</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/440526"&gt;@slee77&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I think this is what you are looking for. I simplified your original data and code.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have ;
	infile datalines ;
	input 
		data_date		:yymmdd8. /* YYMMDD8. */
		seccode			:$4. 
		ME_October_t	:32.		
	;
	put _all_ ;
	format 
		data_date	date7.
		;
datalines;
20200101 0001 1 
20200102 0001 2
20200131 0001 3
20200201 0001 4
20200202 0001 5
20200229 0001 6
20200101 0002 7
20200102 0002 8
20200131 0002 9
20200201 0002 10
20200202 0002 11
20200229 0002 12
20200701 0001 13
20200702 0001 14
20200731 0001 15
20200801 0001 16
20200802 0001 17
20200831 0001 18
20200701 0002 19
20200702 0002 20
20200731 0002 21
20200801 0002 22
20200802 0002 23
20200831 0002 24
;

proc sort 
	data	=work.have
	out		=work.srtdHave ;
	by
		seccode data_date ;
run ;

/* 
	Create a look up dataset containing just end of month data for each secode (work.lookup)
	Add matchDate variable to the master data (work.master). 
	This variable will be used to pull in the me6 value.
*/

data 
	/* Define the work.lookup SAS Dataset */
	work.lookup(
		rename=(
			ME_October_t=me6
			
		)
		keep=
			seccode 
			ME_October_t
			matchDate
						
	)
	work.master
	;
	format matchdate date7. ;
	set work.srtdhave ;
	/* If it's the last day of a month then output that record to the lookup table */
	if day(data_date+1)=1 then do ; /* is the current observation the last in a month? */
		matchDate=intnx("month",data_date,0) ; /* Set the matchDate to the start of the month */
		output work.lookup ;
	end ;
	/* Add a matchDate to the master dataset */
	matchdate=intnx('month',data_date,-6) ;
	output work.master ;
run ;

/* Merge the datasets bu seccode and matchdate if there is a record in the master dataset */
data work.want ;
	merge 
		work.master (in=master)
		work.lookup 
	;
	by 
		seccode matchdate ;
	if master ;
run ;

/**/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 12:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/864039#M341241</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-03-14T12:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag a DAILY variable by six MONTHS and populate a new variable with that value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/864213#M341308</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226241"&gt;@AMSAS&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thanks so much for your input! I was about 80% successful because when I looked at the final product after I merge the 'lookup' and 'master' dataset, I had a few dates spread out throughout my dataset where there were missing values in the 'ME6' variable. I think I figured out why. My original dataset is only showing the days the stock market is open so that means no weekends or holidays. Therefore, some months begin after the 1st of the month or end before the actual end of the month and I think that messes up your code since it's looking for the day('data_date'+1)=1. It won't find that argument to be true in those cases and will skip that month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it's not too much trouble to ask, do you think you could modify the code to reflect this please? I am trying to work on a resolution myself as well. I'm wondering if maybe a bunch of OR arguments may work? For example: IF day('data_date'+1)=1 OR ('data_date'+1)=2 OR ('data_date'-1)=29? I'm grasping at straws right now but I will keep at it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for your time and generosity!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 04:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/864213#M341308</guid>
      <dc:creator>slee77</dc:creator>
      <dc:date>2023-03-15T04:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag a DAILY variable by six MONTHS and populate a new variable with that value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/864265#M341337</link>
      <description>&lt;P&gt;Try the following&lt;BR /&gt;&lt;BR /&gt;Things to note&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I assume you do not have observations for weekend days and holidays - This is a requirement of the source data for the sample code below to work correctly.&lt;/LI&gt;
&lt;LI&gt;The sample data generated excludes weekend days (Sat/Sun), not holidays (as long as #1 is true the code should still work).&lt;/LI&gt;
&lt;LI&gt;In your original code, SECCODE was defined as numeric. As it is a code I would recommend you define it as a character variable.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;The code now makes use of&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p181g1p4bw3phkn1vt5p67xvynd5.htm" target="_self"&gt;FIRST. and LAST. DATA Step Variables&lt;/A&gt;&amp;nbsp;(see the documentation for details)&lt;/LI&gt;
&lt;LI&gt;This assumes you only have a single year of data, see following post for code change to handle multiple years&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Create Sample Data */
/* Data will be 7 days around the 1st of each month in 2023 not including Sat/Sun */
/* Note this does include holidays, I am assuming your source data does not have observations for weekends or holidays */

data work.have ;
	keep
		seccode 
		data_date 
		ME_October_t
	;
	format 
		data_date	date7.
		;
	ME_October_t=0 ;
	do seccode = "0001","0002" ;
		do temp_month=1 to 12 ;
			do data_date=mdy(temp_month,01,2023)-3 to mdy(temp_month,01,2023)+3 ;
				if weekday(data_date) not in (1,7) then do ;
					ME_October_t+1 ;	
					output ;	
				end ;
			end ;
		end ;
	end ;
run ;

/* Need to know what month the data_date is in */
data work.have2 ;
	set work.have ;
	mm=month(data_date) ;
	dow=putn(data_date,"downame3.") ;
run ;


proc sort 
	data	=work.have2
	out		=work.srtdHave ;
	by
		seccode mm data_date ;
run ;


/* 
	Create a look up dataset containing just end of month data for each secode (work.lookup)
	Add matchDate variable to the master data (work.master). 
	This variable will be used to pull in the me6 value.
*/

data 
	/* Define the work.lookup SAS Dataset */
	work.lookup(
		rename=(
			ME_October_t=me6
			
		)
		keep=
			seccode 
			ME_October_t
			matchDate
						
	)
	work.master
	;

	format matchdate date7. ;
	set work.srtdhave ;
	by
		seccode mm data_date ;
	/* If it's the last day of a month then output that record to the lookup table */
	if last.mm then do ; /* is the current observation the last in a month? */
		matchDate=intnx("month",data_date,0) ; /* Set the matchDate to the start of the month */
		output work.lookup ;
	end ;
	/* Add a matchDate to the master dataset */
	matchdate=intnx('month',data_date,-6) ;
	output work.master ;
run ;

proc sort 
	data	=work.lookup
	out		=work.srtdLookup ;
	by
		seccode matchdate ;
run ;

proc sort 
	data	=work.master 
	out		=work.srtdMaster ;
	by
		seccode matchdate ;
run ;


/* Merge the datasets by seccode and matchdate if there is a record in the master dataset */
data work.want ;
	merge 
		work.srtdMaster (in=master)
		work.srtdLookup 
	;
	by 
		seccode matchdate ;
	if master ;
run ;

/**/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 11:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/864265#M341337</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-03-29T11:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag a DAILY variable by six MONTHS and populate a new variable with that value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/866902#M342381</link>
      <description>&lt;P&gt;Thank you so much &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226241"&gt;@AMSAS&lt;/a&gt; ! Your code worked. I just had to do a small tweak to the following original code:&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;/* Need to know what month the data_date is in */
data work.have2 ;
	set work.have ;
	mm=month(data_date) ;
	dow=putn(data_date,"downame3.") ;
run ;&lt;/LI-CODE&gt;&lt;P&gt;Since I have multiple years of data for each 'seccode', I had change the 'mm' variable to reflect both month and year:&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;/* Need to know what month the data_date is in */
data work.have2 ;
	set work.have ;
	mm=100*year(data_date)+ month(data_date);
	dow=putn(data_date,"downame3.") ;
run ;&lt;/LI-CODE&gt;&lt;P&gt;That seems to work. I appreciate all your help with this!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 02:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-a-DAILY-variable-by-six-MONTHS-and-populate-a-new/m-p/866902#M342381</guid>
      <dc:creator>slee77</dc:creator>
      <dc:date>2023-03-29T02:51:26Z</dc:date>
    </item>
  </channel>
</rss>

