<?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 Re: create variable by using array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787821#M251802</link>
    <description>Transpose your long format to a wide format is the easiest way to do this anyways dynamically. Otherwise it's a pain to get the right variable names. As others have indicated though, it's better to have your data in a long format not a wide format but ultimately your choice anyways so use PROC TRANSPOSE to flip Paige's output to a wide format. It's fully dynamic and will scale to whatever quarter or months you want. &lt;BR /&gt;&lt;BR /&gt;Typing out those variable names in code alone would make me cringe at that data structure. I'd recommend using a format to display the variables like that but to use a cleaner name that's easier to type out, but that's my opinion. You can use the LABEL statement on PROC TRANSPOSE to assign a different label to the variable than the variable name.</description>
    <pubDate>Thu, 30 Dec 2021 17:10:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-12-30T17:10:16Z</dc:date>
    <item>
      <title>create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787789#M251783</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have following code and I need to create 19 addtional variables by using today's date (total 20 qtr info) by using 'fyqt1' variable (current qtr info).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desire output should have Qtr 2-2017 to Qtr 1-2022 result. This should auto change when I run this code in month of Jan or Apr.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA have;
   format todaydt mmddyy10.;
   todaydt= date();
   *call symput('todaydt',trim(left(input(todaydt,mmddyy10.))));
 fy   = catx('/',year(todaydt),year(todaydt)+1); 
   fyqt = qtr(datepart(todaydt));

 calyr = year(todaydt);
 calqt   = catx('-',qtr(todaydt),year(todaydt)); 

 fyqt1   = catx('-',qtr(datepart(todaydt)),year(todaydt)+1); 
 var = cat('QTR-', substr(fyqt1, 1) );

   run;&lt;/CODE&gt;&lt;/PRE&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="dht115_0-1640876142653.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67022iCC2419EA92EB3B42/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dht115_0-1640876142653.png" alt="dht115_0-1640876142653.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;desire result:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dht115_1-1640877715220.png" style="width: 1040px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67023iFD535098F62F77F9/image-dimensions/1040x39?v=v2" width="1040" height="39" role="button" title="dht115_1-1640877715220.png" alt="dht115_1-1640877715220.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787789#M251783</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2021-12-30T15:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787792#M251785</link>
      <description>&lt;P&gt;This wide arrangement of data that you want is not a good format to use in further programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better you should produce a long data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    do i=0 to 20;
       cal_qt=intnx('quarter',todaydt,i,'b');
       output;
    end;
    format cal_qt yyq6.;
run;
        &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787792#M251785</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-30T15:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787796#M251787</link>
      <description>&lt;P&gt;This will create all future qtr based on the date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also need to create variable name - not the observation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787796#M251787</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2021-12-30T15:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787797#M251788</link>
      <description>&lt;P&gt;well, you may think you need columns with quarters as variable names, I do not and I propose a programming method that will be easier. Any programming you would do with quarters as variable names will be quite difficult.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What use will you make of variables whose name is quarters? What is the next analysis? Are you performing additional calculations, or creating a report output, or what?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787797#M251788</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-30T15:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787808#M251794</link>
      <description>&lt;P&gt;I need to use historical data to calculate forecast.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 16:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787808#M251794</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2021-12-30T16:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787821#M251802</link>
      <description>Transpose your long format to a wide format is the easiest way to do this anyways dynamically. Otherwise it's a pain to get the right variable names. As others have indicated though, it's better to have your data in a long format not a wide format but ultimately your choice anyways so use PROC TRANSPOSE to flip Paige's output to a wide format. It's fully dynamic and will scale to whatever quarter or months you want. &lt;BR /&gt;&lt;BR /&gt;Typing out those variable names in code alone would make me cringe at that data structure. I'd recommend using a format to display the variables like that but to use a cleaner name that's easier to type out, but that's my opinion. You can use the LABEL statement on PROC TRANSPOSE to assign a different label to the variable than the variable name.</description>
      <pubDate>Thu, 30 Dec 2021 17:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787821#M251802</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-30T17:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787825#M251806</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324991"&gt;@dht115&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to use historical data to calculate forecast.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you are going to do the forecast in SAS then you likely actually want a SAS date value and not some odd value as the timeseries procedures generally want an actual date and not something like "Qtr-1-2022" or "4-2021"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You almost certainly do &lt;STRONG&gt;not&lt;/STRONG&gt; want to use the DATEPART function on a DATE value. Datepart is intended to extract the date from a DATETIME value which is measured in seconds and Dates are measured in days in SAS. So applying datapart to many recent date values results in a value corresponding to something in the 1960s.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 18:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787825#M251806</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-30T18:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787837#M251813</link>
      <description>&lt;P&gt;Where is the DATA for these new variables supposed to come from?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try something like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  today=date();
  do offset=-19 to 0;
    date=intnx('qtr',today,offset);
    string=cat('QTR',put(date,yyqd6.));
    output;
  end;
  format today date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs        today    offset         date     string

  1    30DEC2021      -19     01JAN2017    QTR2017-1
  2    30DEC2021      -18     01APR2017    QTR2017-2
  3    30DEC2021      -17     01JUL2017    QTR2017-3
  4    30DEC2021      -16     01OCT2017    QTR2017-4
  5    30DEC2021      -15     01JAN2018    QTR2018-1
  6    30DEC2021      -14     01APR2018    QTR2018-2
  7    30DEC2021      -13     01JUL2018    QTR2018-3
  8    30DEC2021      -12     01OCT2018    QTR2018-4
  9    30DEC2021      -11     01JAN2019    QTR2019-1
 10    30DEC2021      -10     01APR2019    QTR2019-2
 11    30DEC2021       -9     01JUL2019    QTR2019-3
 12    30DEC2021       -8     01OCT2019    QTR2019-4
 13    30DEC2021       -7     01JAN2020    QTR2020-1
 14    30DEC2021       -6     01APR2020    QTR2020-2
 15    30DEC2021       -5     01JUL2020    QTR2020-3
 16    30DEC2021       -4     01OCT2020    QTR2020-4
 17    30DEC2021       -3     01JAN2021    QTR2021-1
 18    30DEC2021       -2     01APR2021    QTR2021-2
 19    30DEC2021       -1     01JUL2021    QTR2021-3
 20    30DEC2021        0     01OCT2021    QTR2021-4
&lt;/PRE&gt;
&lt;P&gt;What are you going to do with these strings when you have them?&lt;/P&gt;
&lt;P&gt;Do you want to use PROC TRANSPOSE to use the strings as names of the generated variables?&lt;/P&gt;
&lt;P&gt;What values should the variables contain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 18:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787837#M251813</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-30T18:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787839#M251815</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create data set with dates;

data dates;
	*start today;
	today=date();
	*loop through for next 20 periods;

	do offset=-19 to 0;
		*get date;
		date=intnx('qtr', today, offset);
		*create label for date;
		label=cat('QTR ', put(date, qtr.), ' - ', put(date, year4.));
		*create custom variable name;
		var_name=cat('Y', put(date, year4.), '_Q', put(date, qtr.));
		*create fake variable for transposing;
		var=1;
		*write to output data set;
		output;
	end;
	format today date date9.;
run;

*flip to wide structure;

proc transpose data=dates /*input data set*/
	out=want /*output data set*/;
	*specify variable name;
	id var_name;
	*specify variable label;
	idlabel label;
	*specify variable value;
	var var;
run;

*show output with variable labels;
title 'With labels';

proc print data=want label;
run;

*show output without variable labels;
title 'Without labels';

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324991"&gt;@dht115&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have following code and I need to create 19 addtional variables by using today's date (total 20 qtr info) by using 'fyqt1' variable (current qtr info).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desire output should have Qtr 2-2017 to Qtr 1-2022 result. This should auto change when I run this code in month of Jan or Apr.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;DATA have;
   format todaydt mmddyy10.;
   todaydt= date();
   *call symput('todaydt',trim(left(input(todaydt,mmddyy10.))));
 fy   = catx('/',year(todaydt),year(todaydt)+1); 
   fyqt = qtr(datepart(todaydt));

 calyr = year(todaydt);
 calqt   = catx('-',qtr(todaydt),year(todaydt)); 

 fyqt1   = catx('-',qtr(datepart(todaydt)),year(todaydt)+1); 
 var = cat('QTR-', substr(fyqt1, 1) );

   run;&lt;/CODE&gt;&lt;/PRE&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="dht115_0-1640876142653.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67022iCC2419EA92EB3B42/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dht115_0-1640876142653.png" alt="dht115_0-1640876142653.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;desire result:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dht115_1-1640877715220.png" style="width: 1040px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67023iFD535098F62F77F9/image-dimensions/1040x39?v=v2" width="1040" height="39" role="button" title="dht115_1-1640877715220.png" alt="dht115_1-1640877715220.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 19:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787839#M251815</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-30T19:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: create variable by using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787853#M251824</link>
      <description>&lt;P&gt;Time series forecasting is done with long data sets, not wide data sets&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/etsug/etsug_code_ariex02.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/etsug/etsug_code_ariex02.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 21:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-variable-by-using-array/m-p/787853#M251824</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-30T21:30:18Z</dc:date>
    </item>
  </channel>
</rss>

