<?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: Creating a new variable as YEAR:Q from YEAR and SEM imported variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520446#M141125</link>
    <description>&lt;P&gt;Thanks for this. I did not know about this functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Dec 2018 17:14:03 GMT</pubDate>
    <dc:creator>OscarUvalle</dc:creator>
    <dc:date>2018-12-11T17:14:03Z</dc:date>
    <item>
      <title>Creating a new variable as YEAR:Q from YEAR and SEM imported variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/519286#M140638</link>
      <description>&lt;P&gt;Hi! I've been dealing with this problem two weeks ago or so. It is driving me crazy. I'm importing a CSV with three variables&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ID, YEAR and SEM where ID represent a location MX,&amp;nbsp; YEAR the year in 4 digits 2018 and SEM the quarter from 1 to 4. (e.g. MX 2018 1)&lt;/LI&gt;&lt;LI&gt;I am proposing to create a new variable YEARSEM concatenating Year and Sem with a colon between them. (e.g. 2000:1). The problem relies on trying to assign the YEARSEM as YYQC. to be read as time variable by SAS. Many things happen:&lt;OL&gt;&lt;LI&gt;&amp;nbsp;The YEARSEM var is created as string, there is no way to creating as numeric because of the colon,&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;Using the FORMAT YYQC. give me empty values.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;All of this because I have multiple observations for the same id (e.g. CA, 2000, 1 and CA, 2000, 2) therefore I need to create a new time variable&amp;nbsp;to be used as a TIME-ID for regression and others econometrics related stuff which requires&amp;nbsp;one time period observations for each id. Let me know what would you do.&amp;nbsp;&lt;/P&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;DATA Cross;
	INFILE "Cross.csv" DLM = ',' MISSOVER FIRSTOBS = 2;
	FORMAT ID BEST. ;
	FORMAT YEAR YEAR. ;
	FORMAT SEM COMMA1.;
	FORMAT ROA BEST.;
	FORMAT YEARSEM YYQC.;
	INPUT ID  YEAR  Sem  ROA ;
	YEARSEM = CATX(":",YEAR,SEM);
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>Thu, 06 Dec 2018 21:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/519286#M140638</guid>
      <dc:creator>OscarUvalle</dc:creator>
      <dc:date>2018-12-06T21:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable as YEAR:Q from YEAR and SEM imported variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/519294#M140642</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes there is a way to create a date variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date=intnx('qtr', mdy(1,1,year),sem-1,'begin');&lt;/P&gt;
&lt;P&gt;which established a complete date value always assigned to&amp;nbsp;the first day of the specified quarter (i.e. jan1, apr1, jun1, oct1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The just format the date variable as YYQC6.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (the "C" says to put a colon between the 4-digit year and the 1 digit qtr).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For filtering you can then match date literals,&amp;nbsp;as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where date='01jul2018'd;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or quarter membership&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where qtr(date)=3;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 22:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/519294#M140642</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-06T22:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable as YEAR:Q from YEAR and SEM imported variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/519306#M140648</link>
      <description>&lt;P&gt;I would just add to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;'s perfect suggestions that if you require the colon, you can create a custom format.&lt;/P&gt;
&lt;P&gt;See &lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473467.htm" target="_self"&gt;here &lt;/A&gt;and &lt;A href="http://support.sas.com/kb/38/803.html" target="_self"&gt;here &lt;/A&gt;for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 22:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/519306#M140648</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-12-06T22:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable as YEAR:Q from YEAR and SEM imported variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/519324#M140650</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248392"&gt;@OscarUvalle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi! I've been dealing with this problem two weeks ago or so. It is driving me crazy. I'm importing a CSV with three variables&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;ID, YEAR and SEM where ID represent a location MX,&amp;nbsp; YEAR the year in 4 digits 2018 and SEM the quarter from 1 to 4. (e.g. MX 2018 1)&lt;/LI&gt;
&lt;LI&gt;I am proposing to create a new variable YEARSEM concatenating Year and Sem with a colon between them. (e.g. 2000:1). The problem relies on trying to assign the YEARSEM as YYQC. to be read as time variable by SAS. Many things happen:
&lt;OL&gt;
&lt;LI&gt;&amp;nbsp;The YEARSEM var is created as string, there is no way to creating as numeric because of the colon,&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;Using the FORMAT YYQC. give me empty values.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;All of this because I have multiple observations for the same id (e.g. CA, 2000, 1 and CA, 2000, 2) therefore I need to create a new time variable&amp;nbsp;to be used as a TIME-ID for regression and others econometrics related stuff which requires&amp;nbsp;one time period observations for each id. Let me know what would you do.&amp;nbsp;&lt;/P&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;DATA Cross;
	INFILE "Cross.csv" DLM = ',' MISSOVER FIRSTOBS = 2;
	FORMAT ID BEST. ;
	FORMAT YEAR YEAR. ;
	FORMAT SEM COMMA1.;
	FORMAT ROA BEST.;
	FORMAT YEARSEM YYQC.;
	INPUT ID  YEAR  Sem  ROA ;
	YEARSEM = CATX(":",YEAR,SEM);
RUN;&lt;/CODE&gt;&lt;/PRE&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;I am a bit concerned about this statement:&lt;/P&gt;
&lt;P&gt;FORMAT YEAR YEAR. ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not provide any example of the data but since that will by default show a value of 1965 if the actual value of Year is 2018, which is sort of implied by your narrative description, you may lead to a variety of confusions later when using this data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 00:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/519324#M140650</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-07T00:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable as YEAR:Q from YEAR and SEM imported variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520446#M141125</link>
      <description>&lt;P&gt;Thanks for this. I did not know about this functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 17:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520446#M141125</guid>
      <dc:creator>OscarUvalle</dc:creator>
      <dc:date>2018-12-11T17:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable as YEAR:Q from YEAR and SEM imported variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520450#M141126</link>
      <description>Works perfectly. Although, I don't really understand how it works. Would you mind to explain it? I want to know the logic behind each section. MDY(1,1, YEAR) is a function based on the info I got in my YEAR var but what is 1,1 for?. On the other hand, SEM-1, is my var SEM minus 1 but what does that mean?. Lastly, what is function 'BEGIN' for?</description>
      <pubDate>Tue, 11 Dec 2018 17:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520450#M141126</guid>
      <dc:creator>OscarUvalle</dc:creator>
      <dc:date>2018-12-11T17:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable as YEAR:Q from YEAR and SEM imported variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520477#M141140</link>
      <description>&lt;P&gt;First, just parese the structure of the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date=intnx('qtr', mdy(1,1,year),sem-1,'begin');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a function (MDY) inside another function (INTNX)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; For the MDY function google search "sas mdy function", and you will see that it is a way to go the date value of Jan 1 of your given year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So then you have, say for year=2012&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; date = intnx('qtr','01jan2012'd,sem-1,'begin')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Now it's time to google&amp;nbsp; "sas intnx function", which will explain how to start at one date (01jan2012) and establish another date some number of QTRs (or MONTHs, WEEKs, YEARs, etc) after or before 01jan2012.&amp;nbsp; That will also explain the use of SEM-1, and the argument "BEGIN"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Being as the question is restricted to understanding just two functions,&amp;nbsp;it's an excellent context for gaining some familiarity with sas documentation.&amp;nbsp; Seize the moment.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 18:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520477#M141140</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-11T18:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable as YEAR:Q from YEAR and SEM imported variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520878#M141276</link>
      <description>Thank you so much your explanation was clear and concise.</description>
      <pubDate>Wed, 12 Dec 2018 16:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-as-YEAR-Q-from-YEAR-and-SEM-imported/m-p/520878#M141276</guid>
      <dc:creator>OscarUvalle</dc:creator>
      <dc:date>2018-12-12T16:04:44Z</dc:date>
    </item>
  </channel>
</rss>

