<?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 date format from a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415387#M101867</link>
    <description>&lt;P&gt;Dataset attached (&amp;lt;200kb). I had to zip it to upload it.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Nov 2017 06:16:35 GMT</pubDate>
    <dc:creator>BruceBrad</dc:creator>
    <dc:date>2017-11-22T06:16:35Z</dc:date>
    <item>
      <title>Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415368#M101853</link>
      <description>&lt;P&gt;I want to create a format from a dataset to map dates to a price index number. Eg the first row of the dataset is&lt;/P&gt;&lt;P&gt;Start = 01Jan2000&lt;/P&gt;&lt;P&gt;End = 31Mar2000&lt;/P&gt;&lt;P&gt;Value = 0.055&lt;/P&gt;&lt;P&gt;(start and end are SAS date integers)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The format will have elements like&lt;/P&gt;&lt;P&gt;'01Jan2000'd - '31Mar2000'd = 0.055&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This format will then be used as an input statement to create a price variable based on a sas date variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I gather that to do this I need to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;-&amp;nbsp; Convert Start and End variables to character strings of the form '01Jan2000'd (including the quote marks)&lt;/LI&gt;&lt;LI&gt;-&amp;nbsp; Put them into a ctrl dataset and read it into proc format.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The first step seems messy. Any tips? Should I be using SAS date integers (or Julian dates) in the format statement rather than SAS date constants?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 02:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415368#M101853</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2017-11-22T02:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415370#M101855</link>
      <description>&lt;P&gt;Not sure how you want to use it, but here is one way:&lt;/P&gt;
&lt;PRE&gt;data fmtdata;
  retain fmtname 'dates' type 'N';
  input (Start End) (date9. :) label;
  cards;
01Jan2000 31Mar2000 0.055
01Apr2000 30Jun2000 0.044
01Jul2000 30Sep2000 0.033
01Oct2000 31Dec2000 0.022
;

proc format cntlin = fmtdata;
run;

data have;
  input date date9.;
  index=put(date,dates.);
  cards;
3feb2000
7may2000
12jul2000
20nov2000
;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 03:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415370#M101855</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-22T03:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415375#M101859</link>
      <description>&lt;P&gt;Thanks. That's (almost) just what I want. I actually want the index variable to be numeric, but I guess I can create this with&lt;BR /&gt;&amp;nbsp; indexn=input(index,12.0);&lt;/P&gt;&lt;P&gt;after the creation of the index variable in the last datastep. I tried to shortcut this by using a numeric informat and an input statement, but that didn't work.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 05:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415375#M101859</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2017-11-22T05:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415377#M101861</link>
      <description>&lt;P&gt;Just create an informat rather than a format, and then use an input statement. e.g.,:&lt;/P&gt;
&lt;PRE&gt;data fmtdata;
  retain fmtname 'dates' type 'I';
  input (Start End) (date9. :) label;
  cards;
01Jan2000 31Mar2000 0.055
01Apr2000 30Jun2000 0.044
01Jul2000 30Sep2000 0.033
01Oct2000 31Dec2000 0.022
;

proc format cntlin = fmtdata;
run;

data have;
  input date date9.;
  index=input(date,dates.);
  cards;
3feb2000
7may2000
12jul2000
20nov2000
;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 05:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415377#M101861</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-22T05:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415379#M101862</link>
      <description>&lt;P&gt;That's what I tried, but it doesn't work with my code. Can you see anything wrong in this code? The put output at the end has "cpi=." meaning it doesn't find the date in the informat. It works fine if I create a type='n' format and a put rather than input function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data PricesQfmt;
set AUSINC.PricesQ end=last;
if QuarterStartDate &amp;gt;= '01Jan1980'd;  /* restrict to 1980 plus for efficiency */
retain fmtname 'CPIQ2016_17ref' type 'I';
start = put(QuarterStartDate,10.0);
end = put(QuarterEndDate,10.0);
label = put(P2016_17,12.7);
output;
if last then do;
      hlo='O';
      label='.';
      output;
end;
keep Quarter start end fmtname type hlo label ;
run;
proc format cntlin=PricesQfmt;
run;

data test;
testdate = '1jan1981'd;
format testdate date9.;
cpi = input(testdate,cpiQ2016_17ref.);
put testdate= cpi=;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Nov 2017 05:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415379#M101862</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2017-11-22T05:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415382#M101865</link>
      <description>&lt;P&gt;You would have to provide the dataset in order to test it on your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 05:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415382#M101865</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-22T05:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415387#M101867</link>
      <description>&lt;P&gt;Dataset attached (&amp;lt;200kb). I had to zip it to upload it.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 06:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415387#M101867</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2017-11-22T06:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415528#M101917</link>
      <description>&lt;P&gt;You were changing all of your numeric values to character. The following should work:&lt;/P&gt;
&lt;PRE&gt;libname AUSINC '/folders/myfolders';
data PricesQfmt;
set AUSINC.PricesQ (rename=(QuarterStartDate=start P2016_17=label)) end=last;
/* if QuarterStartDate &amp;gt;= '01Jan1980'd;  /* restrict to 1980 plus for efficiency */
if start &amp;gt;= '01Jan1980'd;  /* restrict to 1980 plus for efficiency */
retain fmtname 'CPIQ2016_17ref' type 'I';
/* start = put(QuarterStartDate,10.0); */
/* end = put(QuarterEndDate,10.0); */
end = start;
/* label = put(P2016_17,12.7); */
output;
if last then do;
      hlo='O';
      label='.';
      output;
end;
keep Quarter start end fmtname type hlo label ;
run;
proc format cntlin=PricesQfmt;
run;

data test;
testdate = '1jan1981'd;
format testdate date9.;
cpi = input(testdate,cpiQ2016_17ref.);
put testdate= cpi=;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 14:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415528#M101917</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-22T14:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415713#M101997</link>
      <description>&lt;P&gt;Thanks. That's fixed it. I've also now left the label variable as numeric also - since a numeric output is what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was following an old SUGI article which said the start, end and label variables had to be character. Indeed the SAS help file still implies that this is required. The section on the Output Control Data Set says that Start, End and Label are character variables, and the section on the Input Control Data Set refers back to the Output Control Data Set definition. (This is in SAS 9.4 TS1M3 on X64_7Pro).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 23:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415713#M101997</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2017-11-22T23:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415716#M102000</link>
      <description>&lt;P&gt;Not sure what article you read but, if it said or implied that, it's obviously&amp;nbsp;not correct for numeric formats or informats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 23:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-format-from-a-dataset/m-p/415716#M102000</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-22T23:23:40Z</dc:date>
    </item>
  </channel>
</rss>

