<?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 Import a CSV file with datetime format and new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332036#M74694</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a two step question. I am trying to input the following CSV file into SAS&lt;/P&gt;&lt;P&gt;"quote_id","type","size","price","transaction_datetime"&lt;BR /&gt;21985,"LAST",1000,24.54,"2017-02-09 15:48:30"&lt;BR /&gt;21800,"LAST",1000,24.56,"2017-02-09 15:48:26"&lt;BR /&gt;21166,"LAST",1000,25.01,"2017-02-09 15:45:02"&lt;BR /&gt;21172,"LAST",1000,25.02,"2017-02-09 15:45:04"&lt;BR /&gt;45555,"LAST",1200,24.53,"2017-02-09 20:05:02"&lt;BR /&gt;45549,"LAST",1600,24.52,"2017-02-09 20:04:57"&lt;BR /&gt;45551,"LAST",2000,24.53,"2017-02-09 20:05:01"&lt;BR /&gt;45553,"LAST",2500,24.53,"2017-02-09 20:05:02"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For a project, I am ultimately trying to calculate a price velocity, such as the delta price/delta datetime, so I haven't been able to get my datetime imported correctly in order to calculate the difference. Here is the code I have written so far, and it imports ok. But for my purposes of then calculating the delta price/delta datetime I can't figure out how to make another variable for that. Any thoughts or adivce on #1 how to import the datetime appropriatly (should i be splitting them into two variables) and how is the best way to calculate my delta price/delta time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data import2;
INFILE '/home/test.csv' dsd;
 
 input quote_id symbol $ type $ size price dtvar :ANYDTDTM.;
 
 format dtvar DATETIME19.;
put dtvar= DATETIME19.;
 
 run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 12 Feb 2017 23:30:44 GMT</pubDate>
    <dc:creator>rmiller70</dc:creator>
    <dc:date>2017-02-12T23:30:44Z</dc:date>
    <item>
      <title>Import a CSV file with datetime format and new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332036#M74694</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a two step question. I am trying to input the following CSV file into SAS&lt;/P&gt;&lt;P&gt;"quote_id","type","size","price","transaction_datetime"&lt;BR /&gt;21985,"LAST",1000,24.54,"2017-02-09 15:48:30"&lt;BR /&gt;21800,"LAST",1000,24.56,"2017-02-09 15:48:26"&lt;BR /&gt;21166,"LAST",1000,25.01,"2017-02-09 15:45:02"&lt;BR /&gt;21172,"LAST",1000,25.02,"2017-02-09 15:45:04"&lt;BR /&gt;45555,"LAST",1200,24.53,"2017-02-09 20:05:02"&lt;BR /&gt;45549,"LAST",1600,24.52,"2017-02-09 20:04:57"&lt;BR /&gt;45551,"LAST",2000,24.53,"2017-02-09 20:05:01"&lt;BR /&gt;45553,"LAST",2500,24.53,"2017-02-09 20:05:02"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For a project, I am ultimately trying to calculate a price velocity, such as the delta price/delta datetime, so I haven't been able to get my datetime imported correctly in order to calculate the difference. Here is the code I have written so far, and it imports ok. But for my purposes of then calculating the delta price/delta datetime I can't figure out how to make another variable for that. Any thoughts or adivce on #1 how to import the datetime appropriatly (should i be splitting them into two variables) and how is the best way to calculate my delta price/delta time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data import2;
INFILE '/home/test.csv' dsd;
 
 input quote_id symbol $ type $ size price dtvar :ANYDTDTM.;
 
 format dtvar DATETIME19.;
put dtvar= DATETIME19.;
 
 run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 23:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332036#M74694</guid>
      <dc:creator>rmiller70</dc:creator>
      <dc:date>2017-02-12T23:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Import a CSV file with datetime format and new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332038#M74695</link>
      <description>&lt;P&gt;What is the character variable "symbol" in your input statement. The following worked for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data import2;
INFILE 'c:\art\test.csv' dsd firstobs=2;
 
 input quote_id /*symbol $*/ type $ size price dtvar :ANYDTDTM.;
 
 format dtvar DATETIME19.;
 put dtvar= DATETIME19.;
 
 run;&lt;/PRE&gt;
&lt;P&gt;As for your question about computing a delta, what specific calculation do you want to perform?&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>Mon, 13 Feb 2017 00:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332038#M74695</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-13T00:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Import a CSV file with datetime format and new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332041#M74698</link>
      <description>&lt;P&gt;Thank you, that worked for me as well. I am trying to calculate (row 2 date_time - row 1 date_time)/( row 2 price-row 1) into another column for each respective row. Similar in thought to the lag price. Does that make sense?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 00:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332041#M74698</guid>
      <dc:creator>rmiller70</dc:creator>
      <dc:date>2017-02-13T00:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Import a CSV file with datetime format and new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332043#M74699</link>
      <description>&lt;P&gt;Not sure what your new desired measurement means, but it is easily calculated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data import2;
  INFILE 'c:\art\test.csv' dsd firstobs=2;
 
  input quote_id /*symbol $*/ type $ size price dtvar :ANYDTDTM.;
 
  format dtvar DATETIME19.;
  
  delta=(dtvar-lag(dtvar))/(price-lag(price));
 
 run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 00:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332043#M74699</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-13T00:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import a CSV file with datetime format and new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332044#M74700</link>
      <description>&lt;P&gt;I really appreciate your help, I know its just a simple calculation. I'm just playing around with different ways to analyze data right now and that helps me start manipulating it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 00:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-CSV-file-with-datetime-format-and-new-variable/m-p/332044#M74700</guid>
      <dc:creator>rmiller70</dc:creator>
      <dc:date>2017-02-13T00:52:07Z</dc:date>
    </item>
  </channel>
</rss>

