<?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: how to read change missing date values. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742423#M29194</link>
    <description>thank you so much that helped me a lot and mainly that line to line comment simply super and awesome&lt;BR /&gt;thanks again for your hard work&lt;BR /&gt;</description>
    <pubDate>Wed, 19 May 2021 14:52:00 GMT</pubDate>
    <dc:creator>saidatta</dc:creator>
    <dc:date>2021-05-19T14:52:00Z</dc:date>
    <item>
      <title>how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742328#M29185</link>
      <description>&lt;P&gt;&lt;BR /&gt;data ex1;&lt;BR /&gt;input start yymmdd10. end yymmdd10.;&lt;BR /&gt;format start yymmdd10. end yymmdd10.;&lt;BR /&gt;cards;&lt;BR /&gt;2020-02-03 2020-04-03&lt;BR /&gt;2020-06 2020-06&lt;BR /&gt;2020-12 2020-12&lt;BR /&gt;2020 2020&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i don't know where im doing wrong the missing data have to read and show it as missing but it shows every thing as missing and throws errors only reading first observation please help me&lt;/P&gt;&lt;P&gt;thank you in advance...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 05:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742328#M29185</guid>
      <dc:creator>saidatta</dc:creator>
      <dc:date>2021-05-19T05:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742330#M29186</link>
      <description>&lt;P&gt;Since a date is a specific&amp;nbsp;&lt;U&gt;day&lt;/U&gt;, a string without day or month parts cannot be read as a date.&lt;/P&gt;
&lt;P&gt;You have to first define rules for creating fictitious month and day values when they are missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381214"&gt;@saidatta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;data ex1;&lt;BR /&gt;input start yymmdd10. end yymmdd10.;&lt;BR /&gt;format start yymmdd10. end yymmdd10.;&lt;BR /&gt;cards;&lt;BR /&gt;2020-02-03 2020-04-03&lt;BR /&gt;2020-06 2020-06&lt;BR /&gt;2020-12 2020-12&lt;BR /&gt;2020 2020&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i don't know where im doing wrong the missing data have to read and show it as missing but it shows every thing as missing and throws errors only reading first observation please help me&lt;/P&gt;
&lt;P&gt;thank you in advance...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381214"&gt;@saidatta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;data ex1;&lt;BR /&gt;input start yymmdd10. end yymmdd10.;&lt;BR /&gt;format start yymmdd10. end yymmdd10.;&lt;BR /&gt;cards;&lt;BR /&gt;2020-02-03 2020-04-03&lt;BR /&gt;2020-06 2020-06&lt;BR /&gt;2020-12 2020-12&lt;BR /&gt;2020 2020&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i don't know where im doing wrong the missing data have to read and show it as missing but it shows every thing as missing and throws errors only reading first observation please help me&lt;/P&gt;
&lt;P&gt;thank you in advance...&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>Wed, 19 May 2021 07:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742330#M29186</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-19T07:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742385#M29187</link>
      <description>Please post the output you want to see .</description>
      <pubDate>Wed, 19 May 2021 12:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742385#M29187</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-19T12:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742400#M29189</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381214"&gt;@saidatta&lt;/a&gt;&amp;nbsp;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;stated you are going to need to define some rules to handle dates without month and/or day.&lt;BR /&gt;Still here's a way to solve the issue, note I used a simple rule that states if day or month are missing then assume them to be 01 (i.e. 2020 would become 01Jan2020, 2020-03 becomes 01Mar2020).&lt;BR /&gt;&lt;BR /&gt;The code uses&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n13as9vjfj7aokn1syvfyrpaj7z5.htm" target="_self"&gt;Pattern Matching Using Perl Regular Expressions (PRX)&lt;/A&gt;&amp;nbsp;to identify the format of the input, then takes appropriate action to convert that into a SAS date value&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 ex1;
	retain regExp 0 ;
	if _n_=1 then do ;	
		/* Create a regular expression to identify the different date formats */
		regExp=prxparse("/(\d{4}-\d{2}-\d{2})|(\d{4}-\d{2})|(\d{4})/") ;
	end ;
	input cStart : $10. cEnd : $10. ;
	format start date7. ;
	/* Does cStart contain a format we are looking for? */
	match=prxmatch(regExp,cStart) ;
	if match then do ;
		/* It does! So which format did it have? */
		paren=prxparen(regExp) ;
		put cStart= match= paren= ;
		/* Format 1 is YYYY-MM-DD */
		if paren=1 then do ;
			/* don't do anything here, but we could */			
		end ;
		/* Format 2 is YYYY-MM */
		/* So we will need a rule to set the DD, I used 01" */
		else if paren=2 then do ;
			cStart=trim(cStart)!!"-01" ;
		end ;
		/* Format 3 is YYYY */
		/* So we will need a rule to set the MM and DD, I used -01-01" */
		else if paren=3 then do ;
			cStart=trim(cStart)!!"-01-01" ;
		end ;
		/* Now convert cStart to a SAS date value */ 
		start=inputn(cStart,"yymmdd10.") ;
		put "FINALLY! " cStart= start=date7. ;

	end ;

	
cards;
2020-02-03 2020-04-03
2020-06 2020-06
2020-12 2020-12
2020 2020
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, 19 May 2021 13:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742400#M29189</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-05-19T13:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742407#M29190</link>
      <description>&lt;P&gt;Since (as you already experienced) you can't read the data with the default YYMMDD informat, you need to first read the string into a character variable, and then convert that, while making assumptions for the missing values.&lt;/P&gt;
&lt;P&gt;For this, since the code needs to be reusable, I created this macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_date(in,out);
&amp;amp;out. = mdy(
  coalesce(input(scan(&amp;amp;in.,2,"-"),2.),1),
  coalesce(input(scan(&amp;amp;in.,3,"-"),2.),1),
  input(scan(&amp;amp;in.,1,"-"),4.)
);
drop &amp;amp;in.;
format &amp;amp;out. yymmdd10.;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The string is dissected into three parts, using the SCAN function, and those parts are individually converted to numbers; if a part is missing, the INPUT function will happily return a missing value from the empty string without further complaint.&lt;/P&gt;
&lt;P&gt;By applying the COALESCE function, we then set default values if a certain part is missing, and finally, the MDY function builds the complete date.&lt;/P&gt;
&lt;P&gt;We also assign a format and drop the "in" variable, as it is no longer needed.&lt;/P&gt;
&lt;P&gt;The code to read the data then will look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input c_start :$10. c_end :$10.;
%get_date(c_start,start);
%get_date(c_end,end);
datalines;
2020-02-03 2020-04-03
2020-06 2020-06
2020-12 2020-12
2020 2020
;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;resulting in&lt;/P&gt;
&lt;PRE&gt;start	end
2020-02-03	2020-04-03
2020-06-01	2020-06-01
2020-12-01	2020-12-01
2020-01-01	2020-01-01&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 May 2021 14:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742407#M29190</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-19T14:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742408#M29191</link>
      <description>&lt;P&gt;A different way to parse the date lengths and read to a standard date&lt;/P&gt;
&lt;PRE&gt;data ex1;
   input startchar :$10. endchar :$10.;
   array s (*) startchar endchar;
   array d (*) start end;
   do i= 1 to dim(s);
      select (length(s[i]) );
         when(10) d[i]= input(s[i],yymmdd10.);
         when(7) d[i]= input(catx('-',s[i],'01'),yymmdd10.);
         when(4) d[i]= input(catx('-',s[i],'01','01'),yymmdd10.);
         when(0) d[i]= .;
         otherwise Put "Expected length for: " s[i]=;
      end;
   end;
   drop i;
   format start yymmdd10. end yymmdd10.;
cards;
2020-02-03 2020-04-03
2020-06 2020-06
2020-12 2020-12
2020 2020
;&lt;/PRE&gt;
&lt;P&gt;If you get any "unexpected lengths" then some additional code will be needed to address the specific cases.&lt;/P&gt;
&lt;P&gt;This sets missing month and year to 01 Jan for a year, or missing day of month to day=0.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 15:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742408#M29191</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-19T15:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742410#M29192</link>
      <description>&lt;P&gt;PS don't do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cards;
2020-02-03 2020-04-03
2020-06 2020-06
2020-12 2020-12
2020 2020
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The CARDS or DATALINES block should be terminated by a &lt;EM&gt;single semicolon in column 1 on its own line&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;By using what is seemingly a RUN statement (but it isn't, see the coloring done by the Enhanced Editor), you might ending up receiving the string "run" as data!&lt;/P&gt;
&lt;P&gt;Since the CARDS or DATALINES block, by definition, is the last part of a DATA step, it also constitutes a step boundary, so no RUN is needed at all.&lt;/P&gt;
&lt;P&gt;But if you absolutely like to have a RUN there, do it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cards;
2020-02-03 2020-04-03
2020-06 2020-06
2020-12 2020-12
2020 2020
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 May 2021 14:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742410#M29192</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-19T14:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742418#M29193</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (64).png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59576i08507D8D17139C17/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot (64).png" alt="Screenshot (64).png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; and also for end variable the date that i want to in end date of the month basing on feb and leap etc.&lt;/P&gt;&lt;P&gt;thanks in advance and sorry for my English i'm learning..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 14:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742418#M29193</guid>
      <dc:creator>saidatta</dc:creator>
      <dc:date>2021-05-19T14:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742423#M29194</link>
      <description>thank you so much that helped me a lot and mainly that line to line comment simply super and awesome&lt;BR /&gt;thanks again for your hard work&lt;BR /&gt;</description>
      <pubDate>Wed, 19 May 2021 14:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742423#M29194</guid>
      <dc:creator>saidatta</dc:creator>
      <dc:date>2021-05-19T14:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to read change missing date values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742635#M29201</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input c_start :$10. c_end :$10.;

start='1900-01-01';
end='1900-01-01';

substr(start,1,lengthn(c_start))=substr(c_start,1,lengthn(c_start));
substr(end,1,lengthn(c_end))=substr(c_end,1,lengthn(c_end));

num_start=input(start,yymmdd12.);
num_end=input(end,yymmdd12.);

format num_start num_end yymmdd10.;

datalines;
2020-02-03 2020-04-03
2020-06 2020-06
2020-12 2020-12
2020 2020
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 May 2021 12:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-read-change-missing-date-values/m-p/742635#M29201</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-20T12:00:39Z</dc:date>
    </item>
  </channel>
</rss>

