<?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: Summary data into new variables and proc append in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439957#M13569</link>
    <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is exactly what I was looking for. Thank you for your time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data is downloaded each morning at 02:00 and the SAS-code will enter a setup that runs each morning at 05:00 so it should be okay.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 24 Feb 2018 17:18:15 GMT</pubDate>
    <dc:creator>kristiantdc</dc:creator>
    <dc:date>2018-02-24T17:18:15Z</dc:date>
    <item>
      <title>Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439647#M13548</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to automatize a simple yet&amp;nbsp;time-consuming task.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Everyday I have new data on interviews. I need to keep track of how many interviews are created each day and how many of these interviews are closed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have (variables):&lt;/P&gt;&lt;P&gt;Created (date of creation, e.g. "30/01/2018")&lt;/P&gt;&lt;P&gt;closetim (date when interview is completed, e.g. "02/02/2018")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, what I'm trying to accomplish is to create a dataset with 4 columns:&lt;/P&gt;&lt;P&gt;1st column:&amp;nbsp;which tells me the date of when the data was downloaded (e.g. 03/02/2018),&lt;/P&gt;&lt;P&gt;2nd&amp;nbsp;column = "Created" date&lt;/P&gt;&lt;P&gt;3rd column = "count of interviews&amp;nbsp;with date = &amp;nbsp;"created" date&lt;/P&gt;&lt;P&gt;4th column = "count of observations that has been closed (closetim not equal to missing) where date = "created" date"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, each day I can run the code and append new counts of interviews created and closed to an access database. I have tried to visualise it in the attached screendumps:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-02-23 at 11.29.06.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18778iC1B4619354FF7429/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-02-23 at 11.29.06.png" alt="Screen Shot 2018-02-23 at 11.29.06.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-02-23 at 11.29.35.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18779i916AFAE8436253F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-02-23 at 11.29.35.png" alt="Screen Shot 2018-02-23 at 11.29.35.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated,&lt;/P&gt;&lt;P&gt;Kind regards, Kristian&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS Base 9.4 at work (student assistant), and sas university edition at home.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code so far:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA have;&lt;BR /&gt;SET have;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
	SET have;
	created	= datepart(created);
	closetim	= datepart(closetim);

	ATTRIB created  FORMAT = ddmmyy8.;
	ATTRIB closetim FORMAT = ddmmyy8.;
RUN;

PROC SQL;
	CREATE TABLE newdata AS
			SELECT Created, closetim
		FROM have
		ORDER BY created;
QUIT;

DATA newdata;
	set newdata;
		downloaddate = today();
		ATTRIB downloaddate FORMAT = ddmmyy8.;
RUN;

DATA newdata; 
	SET newdata;
	c_created = count(created);
RUN;

DATA newdata; 
SET newdata; 
	if closetim ^= . then c_closetim = "closed";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 10:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439647#M13548</guid>
      <dc:creator>kristiantdc</dc:creator>
      <dc:date>2018-02-23T10:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439729#M13552</link>
      <description>&lt;P&gt;Although I don't completely follow your requirements, it looks like you need to summarize your data on "Created", and also on "Created", but with an indication that the interview is closed. PROC MEANS and PROC SQL are good choices to do this. The summarized results then need to be merged back with your original dataset. PROC SQL is perfect for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because you posted a picture of your data, nobody can work with it. Take a look at the advice for new posters, and provide your data in a more usable format. Then people can try things, and make suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 15:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439729#M13552</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-02-23T15:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439743#M13554</link>
      <description>&lt;P&gt;Thank you for your answer, Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll try to restate my problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data I have is just about similar to regular paneldata, i.e. I'm tracking how many interviews, created on a given day, have been closed over multiple days/months.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each day I'm downloading the same data. I would expect that after a certain period, say a week, new interviews have been created and some amount of the interviews created in the past - that hasn't been closed - will be now be closed. This is essentially what I would like to create, as pictured in the attachement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I followed your advise and have attached the data which I downloaded today. Hopefully, some SAS wizard is able to get me to the next step.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Kind regards,&amp;nbsp;&lt;BR /&gt;Kristian&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 16:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439743#M13554</guid>
      <dc:creator>kristiantdc</dc:creator>
      <dc:date>2018-02-23T16:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439831#M13558</link>
      <description>&lt;P&gt;Where does data download date come from? Is the data fully refreshed each time or do you have to append the results from each month? I would guess it's a fully refresh each month?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 20:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439831#M13558</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-23T20:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439836#M13559</link>
      <description>It’s refreshed each night, so every morning new “Created” dates are found and some interviews will be closed. So yes, fully refreshed.&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Feb 2018 20:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439836#M13559</guid>
      <dc:creator>kristiantdc</dc:creator>
      <dc:date>2018-02-23T20:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439894#M13565</link>
      <description>&lt;P&gt;Not much wizardry required. A simple SQL should do the job. Below code uses your sample data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
    LENGTH
        created            8
        closetim           8 ;
    FORMAT
        created          DDMMYY10.
        closetim         DDMMYY10. ;
    INFORMAT
        created          DDMMYY10.
        closetim         DDMMYY10. ;
    INFILE 'C:\temp\data.csv'
        firstobs=2
        DLM=';'
        truncover
        DSD ;
    INPUT
        created 
        closetim ;
RUN;

proc sql feedback;
  create table want as
    select
      today() as date_downloaded format=ddmmyy10.,
      created,
      count(created) as count_created,
      count(closetim) as count_closed
    from have
    group by created
    ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ideally the downloaded date doesn't get populated using the today() function as that's the date when you execute the code and not necessarily when you've downloaded the data. If you've got the date of the data somewhere in the filename of the downloaded data or in the data itself then that's where you should retrieve the value for "downloaded date" from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you just need a simple SQL to aggregate your data I believe you could also do everything directly within MS Access (if you want to).&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 00:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439894#M13565</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-02-24T00:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439957#M13569</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is exactly what I was looking for. Thank you for your time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data is downloaded each morning at 02:00 and the SAS-code will enter a setup that runs each morning at 05:00 so it should be okay.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 17:18:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/439957#M13569</guid>
      <dc:creator>kristiantdc</dc:creator>
      <dc:date>2018-02-24T17:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440000#M13571</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/195182"&gt;@kristiantdc&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I always try to design in a way that allows for reprocessing of data or for catch-up runs. Right now you might not see any reason for this... but you never know (i.e. you're sick for a few days and can't process your data).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this reason I'd never use the execution date but I'd ensure that I've got the "data date" somewhere in the actual data or then in the filename itself, i.e. &amp;lt;filename_yyyymmdd.csv - something you could implement as part of your download process.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2018 02:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440000#M13571</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-02-25T02:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440013#M13572</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;That’s an excellent point. I’m not sure whether the possibility of extracting such a date exist in the current setup (the data source comes from an external supplier and thus I’m limited to the variables they can ‘create’, as per say an ‘in-data date’ variable). I’ll definitely check with our supplier tomorrow. Thank you for the advice!</description>
      <pubDate>Sun, 25 Feb 2018 09:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440013#M13572</guid>
      <dc:creator>kristiantdc</dc:creator>
      <dc:date>2018-02-25T09:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440028#M13573</link>
      <description>&lt;P&gt;It’s not in the file name? Or maybe it’s in the file properties, or created date?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/195182"&gt;@kristiantdc&lt;/a&gt; wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;That’s an excellent point. I’m not sure whether the possibility of extracting such a date exist in the current setup (the data source comes from an external supplier and thus I’m limited to the variables they can ‘create’, as per say an ‘in-data date’ variable). I’ll definitely check with our supplier tomorrow. Thank you for the advice!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2018 15:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440028#M13573</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-25T15:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440056#M13574</link>
      <description>&lt;P&gt;The metadata of the .csv file contains the creation date. But how I extract this "created" date of the file and put it into downloaded_date with SAS, I have absolutely no idea about.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2018 18:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440056#M13574</guid>
      <dc:creator>kristiantdc</dc:creator>
      <dc:date>2018-02-25T18:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Summary data into new variables and proc append</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440071#M13576</link>
      <description>&lt;P&gt;Well, that part I can help with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DatasetDates;
	length FileRef $8 OptionName $20 OptionVal $1024;
	keep OptionName OptionVal;

	/* Assign the fileref */
	call missing(FileRef);

	/* Blank, so SAS will assign a file name */
	rc1=filename(FileRef, "/SomeDirectory/SomeFile.csv");

	/* Associate the file name with the dataset or directory */
	if rc1 ^=0 then
		abort;

	/* Open the entry for access by SAS. If it is a directory, zero will be returned */
	EntryID=fopen(FileRef);

	/* Get the number of options for the dataset */
	OptNum=foptnum(EntryID);

	if OptNum=. then
		abort;

	/* Get all of the options for the dataset */
	do OptCount=1 to OptNum;
		OptionName=foptname(EntryID, OptCount);
		OptionVal=finfo(EntryID, OptionName);

		if OptionName="Last Modified" then
			output;
	end;

	/* Close the directory */
	rc2=fclose(EntryID);

	if rc2 ^=0 then
		abort;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Feb 2018 20:26:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Summary-data-into-new-variables-and-proc-append/m-p/440071#M13576</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-02-25T20:26:54Z</dc:date>
    </item>
  </channel>
</rss>

