<?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 Create New Variable by Getting Begining and Ending Value - Need Short Fix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value-Need/m-p/565354#M158716</link>
    <description>&lt;P&gt;Helle everybody,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;&amp;nbsp;, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&amp;nbsp;I made it&amp;nbsp; my following question -&amp;gt; &lt;A href="https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value/m-p/529693#M144768" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value/m-p/529693#M144768&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I want to do little changes in my question;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;let's say that I have a following population ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length ID 8 DateCharacter $ 32;
Infile Datalines Missover;
Input  ID DateCharacter;
Datalines;
1 201601
1 201602
1 201603
1 201604
1 201605
1 201606
1 201607
1 201608
1 201609
1 201610
1 201611
1 201612
2 201605
2 201606
2 201607
2 201608
2 201609
2 201610
2 201611
2 201612
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of following view;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OldView.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30216i58D3CEBA6C8ED7D3/image-size/large?v=v2&amp;amp;px=999" role="button" title="OldView.png" alt="OldView.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to see whole periods and table_names same -&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="New_View.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30217i00CCF20E43635522/image-size/large?v=v2&amp;amp;px=999" role="button" title="New_View.png" alt="New_View.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As I tried to say as above; if 01MAY2016 is equal to period 5 in 12 months range then every 01may2016 should equal to period 5 same for other months. And table_name variable should be constant, as you can see in the image.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We need to count distinct YearMonth values then give the range between Begining and Ending Value and then assign the period values for this range. I hope I could make myself clear?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If can somebody help about this, I would be so happy.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2019 18:43:58 GMT</pubDate>
    <dc:creator>turcay</dc:creator>
    <dc:date>2019-06-11T18:43:58Z</dc:date>
    <item>
      <title>Create New Variable by Getting Begining and Ending Value - Need Short Fix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value-Need/m-p/565354#M158716</link>
      <description>&lt;P&gt;Helle everybody,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;&amp;nbsp;, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&amp;nbsp;I made it&amp;nbsp; my following question -&amp;gt; &lt;A href="https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value/m-p/529693#M144768" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value/m-p/529693#M144768&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I want to do little changes in my question;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;let's say that I have a following population ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length ID 8 DateCharacter $ 32;
Infile Datalines Missover;
Input  ID DateCharacter;
Datalines;
1 201601
1 201602
1 201603
1 201604
1 201605
1 201606
1 201607
1 201608
1 201609
1 201610
1 201611
1 201612
2 201605
2 201606
2 201607
2 201608
2 201609
2 201610
2 201611
2 201612
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of following view;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OldView.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30216i58D3CEBA6C8ED7D3/image-size/large?v=v2&amp;amp;px=999" role="button" title="OldView.png" alt="OldView.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to see whole periods and table_names same -&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="New_View.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30217i00CCF20E43635522/image-size/large?v=v2&amp;amp;px=999" role="button" title="New_View.png" alt="New_View.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As I tried to say as above; if 01MAY2016 is equal to period 5 in 12 months range then every 01may2016 should equal to period 5 same for other months. And table_name variable should be constant, as you can see in the image.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We need to count distinct YearMonth values then give the range between Begining and Ending Value and then assign the period values for this range. I hope I could make myself clear?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If can somebody help about this, I would be so happy.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 18:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value-Need/m-p/565354#M158716</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2019-06-11T18:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variable by Getting Begining and Ending Value - Need Short Fix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value-Need/m-p/566490#M159218</link>
      <description>&lt;P&gt;Maybe this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Get the first and last date for each group;
proc sql noprint;
	create table have_2 as 
	select *, min(DateCharacter) as period_start, max(DateCharacter) as period_end 
	from have
	group by ID
	order by ID, DateCharacter;
quit;


data want;
	set have_2;
	retain period;
	by id;

	*Fix the string dates to be SAS dates.;
	_d=cats(DateCharacter,"01");
	_d_start=input(cats(period_start,"01"),yymmdd10.);
	_d_end=input(cats(period_end,"01"),yymmdd10.);
	d=input(_d,yymmdd10.);

	*Count the number of periods for this ID.;
	if first.id then period = 1;
	else period = period + 1;

	*Fix the table name by concatination.;
	table_name = cats(put(_d_start,date9.),"_",put(_d_end,date9.));
	format d yymmdd10.;
	*Get rid of temporary variables;
	drop _d: period_start period_end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;BTW, it is a bit confusing that you have to look at two messages to try to figure out what you want. Better to rewrite it to one instead. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 03:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-New-Variable-by-Getting-Begining-and-Ending-Value-Need/m-p/566490#M159218</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-06-17T03:39:08Z</dc:date>
    </item>
  </channel>
</rss>

