<?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: Month/day switched when importing cvs file with datetime variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904927#M83156</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460320"&gt;@JKHess&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes, I did modify the code in the log file when I changed the informat from anydtdtm40. to anydtdte40. Not sure what else to try.&lt;BR /&gt;&lt;BR /&gt;It's not reading all the dates wrong (or differently from MS), just some of them.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;These informats are not the ones you want to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to identify the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/allprodslang/syntaxByCategory-informat.htm#n1d18o4bh2i869n1ecks0tifltc8" target="_self"&gt;specific informats&lt;/A&gt; that will allow you to read the dates properly. It may be that you want to switch from the MMDDYY informat to the DDMMYY informat, or &lt;EM&gt;vice versa&lt;/EM&gt;. Providing examples of the dates in the CSV file would be very helpful.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Nov 2023 16:44:12 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-11-28T16:44:12Z</dc:date>
    <item>
      <title>Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904883#M83151</link>
      <description>Hi, when importing a large csv file with several datetime variables, there is a discrepancy between the value SAS assigns vs the value Microsoft products (excel, power BI) assign, specifically, the month and day are switched for some but not all of the dates (e.g., Jan 4 in SAS, April 1 in MS). Has anyone run into this? How can I determine which is correct? Note, the informat statement defaulted to anydtdtm40., but I also tried anydtdte40. and got the same result.&lt;BR /&gt;&lt;BR /&gt;Code below:&lt;BR /&gt;PROC IMPORT OUT= WORK.z&lt;BR /&gt;DATAFILE= "C:\filename.csv"&lt;BR /&gt;DBMS=CSV REPLACE;&lt;BR /&gt;GETNAMES=YES;&lt;BR /&gt;DATAROW=2;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data z2;&lt;BR /&gt;set z;&lt;BR /&gt;i_date=datepart(i_datetime);&lt;BR /&gt;format i_date mmddyy8.;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Nov 2023 15:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904883#M83151</guid>
      <dc:creator>JKHess</dc:creator>
      <dc:date>2023-11-28T15:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904912#M83152</link>
      <description>&lt;P&gt;PROC IMPORT is a guessing procedure. In this case, it guessed wrong. However, the actual code it uses to import the CSV file is provided in the log, you can copy this code, modify it to produce the correct dates, and run it again.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 16:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904912#M83152</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-28T16:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904914#M83153</link>
      <description>Yes, I did modify the code in the log file when I changed the informat from anydtdtm40. to anydtdte40. Not sure what else to try.&lt;BR /&gt;&lt;BR /&gt;It's not reading all the dates wrong (or differently from MS), just some of them.</description>
      <pubDate>Tue, 28 Nov 2023 16:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904914#M83153</guid>
      <dc:creator>JKHess</dc:creator>
      <dc:date>2023-11-28T16:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904915#M83154</link>
      <description>Would you be able to provide examples of the data you have?</description>
      <pubDate>Tue, 28 Nov 2023 16:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904915#M83154</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2023-11-28T16:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904925#M83155</link>
      <description>It's this file: &lt;A href="https://data.cityofnewyork.us/Public-Safety/EMS-Incident-Dispatch-Data/76xm-jjuj" target="_blank"&gt;https://data.cityofnewyork.us/Public-Safety/EMS-Incident-Dispatch-Data/76xm-jjuj&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;It's too big for me to open it with a text editor.</description>
      <pubDate>Tue, 28 Nov 2023 16:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904925#M83155</guid>
      <dc:creator>JKHess</dc:creator>
      <dc:date>2023-11-28T16:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904927#M83156</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460320"&gt;@JKHess&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes, I did modify the code in the log file when I changed the informat from anydtdtm40. to anydtdte40. Not sure what else to try.&lt;BR /&gt;&lt;BR /&gt;It's not reading all the dates wrong (or differently from MS), just some of them.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;These informats are not the ones you want to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to identify the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/allprodslang/syntaxByCategory-informat.htm#n1d18o4bh2i869n1ecks0tifltc8" target="_self"&gt;specific informats&lt;/A&gt; that will allow you to read the dates properly. It may be that you want to switch from the MMDDYY informat to the DDMMYY informat, or &lt;EM&gt;vice versa&lt;/EM&gt;. Providing examples of the dates in the CSV file would be very helpful.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 16:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904927#M83156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-28T16:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904932#M83158</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460320"&gt;@JKHess&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;It's this file: &lt;A href="https://data.cityofnewyork.us/Public-Safety/EMS-Incident-Dispatch-Data/76xm-jjuj" target="_blank" rel="noopener"&gt;https://data.cityofnewyork.us/Public-Safety/EMS-Incident-Dispatch-Data/76xm-jjuj&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;It's too big for me to open it with a text editor.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you use the wrong editor. Something like Notepad++ should not be overwhelmed by size.&lt;/P&gt;
&lt;P&gt;Alternatively, this SAS method can also help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile "C:\filename.csv" lrecl=32767 obs=10;
input;
list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which shows the contents in the log, or this one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile "C:\filename.csv" lrecl=32767 obs=10;
length line $32767;
input;
line = _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which puts the lines into a dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 17:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904932#M83158</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-28T17:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904934#M83159</link>
      <description>&lt;P&gt;PROC IMPORT will use ANY... series of informats.&amp;nbsp; Those will use the setting of the DATESTYLE option to decide what to do with ambiguous strings like 01/04/2023 which could mean first of April to some people and January fourth to others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for a CSV file just write you own data step to read the file and you can use the appropriate informat instead.&amp;nbsp; MMDDYY or DDMMYY.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 17:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904934#M83159</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-28T17:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904937#M83160</link>
      <description>&lt;P&gt;If the example shown is correct then the data appears in YYYY MON DD HH:MM:SS am/pm structure. Which is nearly one of the stupidest data storage formats I have seen in a long time. (MON means three letter month abbreviation)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is one way to parse the values. It would require reading all the values as strings, then using an array to loop over them to process and assign the values to another array for the datetime value.&lt;/P&gt;
&lt;PRE&gt;data junk;
  string = '2023 Oct 01 12:15:23 AM';
  dt = dhms(input(cats(scan(string,3),scan(string,2),scan(string,1)),date9.),0,0,input(cats(scan(string,4),scan(string,4)),time10.));
  format dt datetime20.;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2023 17:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904937#M83160</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-11-28T17:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904940#M83161</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;said, PROC IMPORT is guessing as to the meaning of values it reads from the CSV.&amp;nbsp; If you use Excel to read a CSV, it also will guess, and I suspect PowerBI will guess as well.&amp;nbsp; When you use the anydt* informats, you are telling SAS to guess the meaning, because you don't know if the date could be mm/dd/yyyy or yyyy/mm/dd or one of many other possible formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If PROC IMPORT, Excel, and PowerBI are making different guesses as to the meaning of a date value stored in a CSV, there is no good way to know which guess is correct.&amp;nbsp; You would need to ask the source of the CSV about the meaning of each value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully the source will tell you that there is a consistent date format used for a variable.&amp;nbsp; Then in SAS, you would specify the appropriate specific informat when you read in the data.&amp;nbsp; The goal is to avoid guessing, which can always go wrong.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 18:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904940#M83161</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-11-28T18:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904953#M83162</link>
      <description>&lt;P&gt;So the CSV export from that site messes up the datetime fields.&lt;/P&gt;
&lt;P&gt;But if you use the API interface it generates the datetime fields in ISO standard format.&lt;/P&gt;
&lt;P&gt;So copy the file yourself to a CSV file and it should be easier to read it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile  "https://data.cityofnewyork.us/resource/76xm-jjuj.csv?$limit=30000000"  url ;
  file 'nycems.csv';
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2023 19:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904953#M83162</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-28T19:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904969#M83163</link>
      <description>&lt;P&gt;Once you have a valid CSV file you can use&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_self"&gt; %CSV2DS()&lt;/A&gt; to help you GUESS how to read it.&lt;/P&gt;
&lt;P&gt;You will need to use the PRECENT= option to sample a subset of the rows since over 25 million observations will overwhelm PROC SQL's ability to summarize the data types.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%csv2ds('c:\downloads\nycems.csv',out=nycems,percent=1,replace=1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Resulting SAS code:&lt;/P&gt;
&lt;PRE&gt;data nycems;
  infile 'c:\downloads\nycems.csv' dlm=',' dsd truncover firstobs=2 ;
  length cad_incident_id 8 incident_datetime 8 initial_call_type $6
    initial_severity_level_code 8 final_call_type $6
    final_severity_level_code 8 first_assignment_datetime 8
    valid_dispatch_rspns_time_indc $5 dispatch_response_seconds_qy 8
    first_activation_datetime 8 first_on_scene_datetime 8
    valid_incident_rspns_time_indc $5 incident_response_seconds_qy 8
    incident_travel_tm_seconds_qy 8 first_to_hosp_datetime 8
    first_hosp_arrival_datetime 8 incident_close_datetime 8
    held_indicator $5 incident_disposition_code 8 borough $24
    incident_dispatch_area $2 zipcode 8 policeprecinct 8
    citycouncildistrict 8 communitydistrict 8 communityschooldistrict 8
    congressionaldistrict 8 reopen_indicator $5 special_event_indicator $5
    standby_indicator $5 transfer_indicator $5
  ;
  informat incident_datetime anydtdtm. first_assignment_datetime anydtdtm.
    first_activation_datetime anydtdtm. first_on_scene_datetime anydtdtm.
    first_to_hosp_datetime anydtdtm. first_hosp_arrival_datetime anydtdtm.
    incident_close_datetime anydtdtm. zipcode comma.
  ;
  format incident_datetime datetime19.
    first_assignment_datetime datetime19.
    first_activation_datetime datetime19.
    first_on_scene_datetime datetime19. first_to_hosp_datetime datetime19.
    first_hosp_arrival_datetime datetime19.
    incident_close_datetime datetime19. zipcode comma6.
  ;
  input cad_incident_id -- transfer_indicator ;
run;
&lt;/PRE&gt;
&lt;P&gt;You should probably remove the FORMAT from ZIPCODE since you don't want to replicate the mistake in the data and print the values with thousands separators.&lt;/P&gt;
&lt;P&gt;You also will probably want to standardize the "indicator" variables to consistently use Y/N instead of sometimes using true/false.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 20:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/904969#M83163</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-28T20:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905004#M83165</link>
      <description>&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
invalue $yntf 'Y','true'='Y' 'N','false'='N';
run;


data nycems;
  infile  "c:\downloads\nycems.csv"  dlm=',' dsd truncover firstobs=2 ;
  length cad_incident_id 8 incident_datetime 8 initial_call_type $6
    initial_severity_level_code 8 final_call_type $6
    final_severity_level_code 8 first_assignment_datetime 8
    valid_dispatch_rspns_time_indc $1 dispatch_response_seconds_qy 8
    first_activation_datetime 8 first_on_scene_datetime 8
    valid_incident_rspns_time_indc $1 incident_response_seconds_qy 8
    incident_travel_tm_seconds_qy 8 first_to_hosp_datetime 8
    first_hosp_arrival_datetime 8 incident_close_datetime 8
    held_indicator $1 incident_disposition_code 8 borough $24
    incident_dispatch_area $2 zipcode 8 policeprecinct 8
    citycouncildistrict 8 communitydistrict 8 communityschooldistrict 8
    congressionaldistrict 8 reopen_indicator $1 special_event_indicator $1
    standby_indicator $1 transfer_indicator $1
  ;
  informat incident_datetime first_assignment_datetime 
    first_activation_datetime first_on_scene_datetime 
    first_to_hosp_datetime  first_hosp_arrival_datetime 
    incident_close_datetime anydtdtm.
    zipcode comma.
    valid_dispatch_rspns_time_indc valid_incident_rspns_time_indc  
    held_indicator reopen_indicator special_event_indicator standby_indicator 
    transfer_indicator $yntf.
  ;
  format incident_datetime 
    first_assignment_datetime 
    first_activation_datetime 
    first_on_scene_datetime  first_to_hosp_datetime 
    first_hosp_arrival_datetime 
    incident_close_datetime datetime19.
  ;
  input cad_incident_id -- transfer_indicator ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2023 21:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905004#M83165</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-28T21:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905010#M83166</link>
      <description>&lt;P&gt;Modifying&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;'s code very slightly to read from the URL directly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename src url 'https://data.cityofnewyork.us/resource/76xm-jjuj.csv';

proc format ;
invalue $yntf 'Y','true'='Y' 'N','false'='N';
run;


data nycems;
  infile  src  dlm=',' dsd truncover firstobs=2 ;
  length cad_incident_id 8 incident_datetime 8 initial_call_type $6
    initial_severity_level_code 8 final_call_type $6
    final_severity_level_code 8 first_assignment_datetime 8
    valid_dispatch_rspns_time_indc $1 dispatch_response_seconds_qy 8
    first_activation_datetime 8 first_on_scene_datetime 8
    valid_incident_rspns_time_indc $1 incident_response_seconds_qy 8
    incident_travel_tm_seconds_qy 8 first_to_hosp_datetime 8
    first_hosp_arrival_datetime 8 incident_close_datetime 8
    held_indicator $1 incident_disposition_code 8 borough $24
    incident_dispatch_area $2 zipcode 8 policeprecinct 8
    citycouncildistrict 8 communitydistrict 8 communityschooldistrict 8
    congressionaldistrict 8 reopen_indicator $1 special_event_indicator $1
    standby_indicator $1 transfer_indicator $1
  ;
  informat incident_datetime first_assignment_datetime 
    first_activation_datetime first_on_scene_datetime 
    first_to_hosp_datetime  first_hosp_arrival_datetime 
    incident_close_datetime anydtdtm.
    zipcode comma.
    valid_dispatch_rspns_time_indc valid_incident_rspns_time_indc  
    held_indicator reopen_indicator special_event_indicator standby_indicator 
    transfer_indicator $yntf.
  ;
  format incident_datetime 
    first_assignment_datetime 
    first_activation_datetime 
    first_on_scene_datetime  first_to_hosp_datetime 
    first_hosp_arrival_datetime 
    incident_close_datetime datetime19.
  ;
  input cad_incident_id -- transfer_indicator ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 21:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905010#M83166</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-11-28T21:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905054#M83168</link>
      <description>&lt;P&gt;Modifying &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; suggest code just a bit:&lt;/P&gt;
&lt;P&gt;Custom informat:&lt;/P&gt;
&lt;PRE&gt;proc format ;
invalue yntf (upcase)
'Y','YES','T','TRUE'=1
'N','NO','F','FALSE'=0
;
run;&lt;/PRE&gt;
&lt;P&gt;And use Yntf (not character $Yntf ) informat. The counting of yes/no/true/false values quite often goes much easier using numeric as then Proc means/summary or the report procedures Report and Tabulate can get counts of Yes (sum statistic) percent as decimal value (mean statistic) and it is easier if you need to get something like that from multiple variables on a record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that I added a couple of guessed other values that might appear just in case in the informat YES, NO, T, F and the upcase option will deal with possible changes in case down the line.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 23:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905054#M83168</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-11-28T23:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905186#M83169</link>
      <description>&lt;P&gt;Thanks so much...I'm running this now. What I'm still confused about is why SAS apparently mixed formats when reading in the file. If it decided that the format was dd/mm/yyyy instead of mm/dd/yyyy, then why did it correctly read in dates that had a 'day' value&amp;gt;12?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2023 15:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905186#M83169</guid>
      <dc:creator>JKHess</dc:creator>
      <dc:date>2023-11-29T15:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905202#M83170</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460320"&gt;@JKHess&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks so much...I'm running this now. What I'm still confused about is why SAS apparently mixed formats when reading in the file. If it decided that the format was dd/mm/yyyy instead of mm/dd/yyyy, then why did it correctly read in dates that had a 'day' value&amp;gt;12?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To cite&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1701274842247.png" style="width: 1650px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90442i203D698D948A867B/image-dimensions/1650x33?v=v2" width="1650" height="33" role="button" title="Patrick_1-1701274842247.png" alt="Patrick_1-1701274842247.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The value of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_044/lesysoptsref/n0cmg3tjkn6zmbn1od6pna244zm7.htm" target="_self"&gt;DATESTYLE&lt;/A&gt; option drives if an ANY... informat first will attempt to read a date string as mm/dd/yyyy or as dd/mm/yyyy. For a date string with a 'day' value&amp;gt;12 there is only one option how to read the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What appears to be the case is that in your environment the datestyle option is set to first try dd/mm but the data uses mm/dd. You just need to change the value of the option to mdy&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_2-1701275181345.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90443iE9CD6F9FEF4A31C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_2-1701275181345.png" alt="Patrick_2-1701275181345.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sv_datestyle=%sysfunc(getoption(datestyle,keyword));
options datestyle=mdy;

* your proc import code ;

/* reset option to initial value to not change the behaviour for later code in the same SAS session */
options &amp;amp;sv_datestyle;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2023 16:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905202#M83170</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-29T16:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905208#M83171</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460320"&gt;@JKHess&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks so much...I'm running this now. What I'm still confused about is why SAS apparently mixed formats when reading in the file. If it decided that the format was dd/mm/yyyy instead of mm/dd/yyyy, then why did it correctly read in dates that had a 'day' value&amp;gt;12?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS did NOT switch format (I think you meant INFORMAT).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that the file you get with the Export CSV option uses an AMBIGUOUS style for the text of the DATETIME fields.&amp;nbsp; It has text in the style AA BB CCCC DD:EE FF.&amp;nbsp; &amp;nbsp;That is why I said to use the file produced by the API url instead.&amp;nbsp; That file has the datetime strings in the unambiguous ISO format of YYYYMMDDThhmmss.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;PROC IMPORT did not know of a SAS informat that could read that so it used ANYDTDTM informat which can handle many different styles, picking the one it thinks best matches the current string's value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the value of either AA or BB is larger than 12 then it is obvious which one is the DAY and which one is the MONTH.&amp;nbsp; But for a value like '01 04 ...' either one could be the month.&amp;nbsp; &amp;nbsp; &amp;nbsp;In that case the ANYDT... informats use the setting of the DATESTYLE system option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is normally set to use the order most often used by the country indicated by the LOCALE setting.&amp;nbsp; So in the US it would assume 01 04 is January fourth.&amp;nbsp; But in Europe it might assume you wanted first of April.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have one order you want it to use the set the DATESTYLE option before the call to PROC IMPORT.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since this data is from NYC you should set DATESTYLE to MDY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2023 16:41:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905208#M83171</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-29T16:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905310#M83172</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460320"&gt;@JKHess&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks so much...I'm running this now. What I'm still confused about is why SAS apparently mixed formats when reading in the file. If it decided that the format was dd/mm/yyyy instead of mm/dd/yyyy, then why did it correctly read in dates that had a 'day' value&amp;gt;12?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is why you&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;don't use PROC IMPORT for csv files; instead write the DATA step yourself, according to the description of the file&lt;/LI&gt;
&lt;LI&gt;don't use the ANY... informats in your DATA step. Either use a fitting available informat, or read the data as a string and parse it&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 30 Nov 2023 06:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905310#M83172</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-30T06:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Month/day switched when importing cvs file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905874#M83173</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Is there additional code needed to run this macro? I'm getting a warning and an error. I think I need to identify where the macro code is found?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%csv2ds("c:\Users\judyk\nycems.csv",out=nycems,percent=1,replace=1);&lt;BR /&gt;-&lt;BR /&gt;180&amp;nbsp;WARNING: Apparent invocation of macro CSV2DS not resolved.&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Dec 2023 05:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Month-day-switched-when-importing-cvs-file-with-datetime/m-p/905874#M83173</guid>
      <dc:creator>JKHess</dc:creator>
      <dc:date>2023-12-03T05:21:50Z</dc:date>
    </item>
  </channel>
</rss>

