<?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: where is the Day1 and Day2 variable ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748041#M234893</link>
    <description>&lt;P&gt;Maxim 2&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;&lt;STRONG&gt;Read the Log.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;&lt;STRONG&gt;Read the Log.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;&lt;STRONG&gt;Read the Log.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jun 2021 06:57:33 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-06-15T06:57:33Z</dc:date>
    <item>
      <title>where is the Day1 and Day2 variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748016#M234879</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;First, I create a data set as following:&lt;BR /&gt;libname apple 'C:\Users\liaodong\Documents\My SAS Files\prep guide\base
\70 question\question 57';
data apple.one;
length BeginDate $ 9.;
input BeginDate $ ;
datalines;
09JAN2010
12JAN2010
;
proc print data = apple.one;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then, I input data set above:&lt;/P&gt;
&lt;P&gt;libname apple 'C:\Users\liaodong\Documents\My SAS Files\prep guide\base&lt;BR /&gt;\70 question\question 57';&lt;BR /&gt;data apple.two;&lt;BR /&gt;set apple.one;&lt;BR /&gt;Day1 = weekday(BeginDate);&lt;BR /&gt;Day2 = day(BeginDate);&lt;BR /&gt;format BeginDate date9.;&lt;BR /&gt;run;&lt;BR /&gt;proc print data = apple.two;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that there should be three variable , BeginDate , Day1 and Day2 ?&lt;/P&gt;
&lt;P&gt;But the result is not&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tianerhu_0-1623724231436.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60388i7835A166CF2401DC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_0-1623724231436.png" alt="tianerhu_0-1623724231436.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;where are the Day1 and Day2?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 02:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748016#M234879</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-06-15T02:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: where is the Day1 and Day2 variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748020#M234883</link>
      <description>&lt;P&gt;Is there an error in the log when creating the data set "apple.two"?&lt;BR /&gt;The error suggests that the dataset was not created correctly, so the proc print step prints the dataset "apple.one" that was created successfully just before.&lt;/P&gt;
&lt;P&gt;As for the error, I think it is because BeginDate is a character variable, so the date9 format cannot be applied.&lt;BR /&gt;If you use the input function to convert it to a date value and then process it as shown below, you may get the desired result.&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 apple.two;
  set apple.one;
  Day1 = weekday(input(BeginDate,date9.));
  Day2 = day(input(BeginDate,date9.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 03:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748020#M234883</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-06-15T03:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: where is the Day1 and Day2 variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748033#M234886</link>
      <description>&lt;P&gt;If you look closely in your SAS log, there will be errors listed.&amp;nbsp; One issue is that BeginDate cannot be character.&amp;nbsp; Date functions like DAY() and WEEKDAY() do not work on character data.&amp;nbsp; They only work on numeric data.&amp;nbsp; Dates in SAS are store as numbers (the count of days starting on Jan 1st, 1960).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1623734678751.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60390i3C059546333D0958/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1623734678751.png" alt="jimbarbour_0-1623734678751.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You need to first read in the data as character and then transform it into a true SAS value using the INPUT() function.&amp;nbsp; The INPUT() function converts characters into numbers based on the INFORMAT specified.&amp;nbsp; Here, I am using ANYDTDTE which will read in almost any date or date-time type variable and extract the date.&amp;nbsp; Once you have transformed the data, &lt;EM&gt;then&lt;/EM&gt; you can use&amp;nbsp; DAY() and WEEKDAY().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've adjusted the code as follows, below.&amp;nbsp; Below that are the results.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
	DROP	_:;
	length BeginDate	8;
	length _Temp_Date	$9;
	input _Temp_Date 	$ ;

	BeginDate	=	INPUT(_Temp_Date, ANYDTDTE9.);

datalines;
09JAN2010
12JAN2010
;
proc print data = one;
run;

data two;
	set one;
	Day1 = weekday(BeginDate);
	Day2 = day(BeginDate);
	format BeginDate date9.;
run;

proc print data = two;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_1-1623734899395.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60391i91B9A482C017058A/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_1-1623734899395.png" alt="jimbarbour_1-1623734899395.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 05:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748033#M234886</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-15T05:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: where is the Day1 and Day2 variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748034#M234887</link>
      <description>&lt;P&gt;Read the log, always! Especially if the result of a program does not meet your expectations. &lt;/P&gt;
&lt;P&gt;The problem (BeginDate is a char-variable) is reported in the second step, but caused by not properly reading the variable in the first data step. So i would fix the problem there:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.one;
   length BeginDate 8; /* &amp;lt;- changed to numeric */
   
  /* informat so that the variable BeginDate  */
   format BeginDate date9.;
   informat BeginDate date9.;
   
   input BeginDate;
   datalines;
09JAN2010
12JAN2010
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jun 2021 05:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748034#M234887</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-06-15T05:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: where is the Day1 and Day2 variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748041#M234893</link>
      <description>&lt;P&gt;Maxim 2&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;&lt;STRONG&gt;Read the Log.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;&lt;STRONG&gt;Read the Log.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;&lt;STRONG&gt;Read the Log.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 06:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-is-the-Day1-and-Day2-variable/m-p/748041#M234893</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-15T06:57:33Z</dc:date>
    </item>
  </channel>
</rss>

