I am trying to read 20 march 2011 date using worddatx32. format but it cant read it gives an error was not found or could not be loaded.
I also try anydtdte32. but it give . in output
how can I read 20 march 2011 date in data lines
data sample;
infile datalines truncover dsd;
input JDate : worddatx32.;
format JDate date9.;
datalines;
20 march 2011
;
run;
WORDDATX. is a FORMAT and you need an INFORMAT. Try using ANYDTDTE. as the informat.
data test ;
input xx anydtdte32. ;
format xx date9.;
put xx= #15 _infile_;
cards;
20 march 2016
20MAR2016
;
Also if you are going to use the : modifier then SAS will stop at the space and only read the 20. Add the & modifier and it will stop when it sees two or more spaces. Of if you are using delimited input then just use an INFORMAT statement.
data test ;
infile cards dsd truncover ;
input xx ;
informat xx anydtdte. ;
format xx date9.;
put xx= #15 _infile_;
cards;
20 march 2016
20MAR2016
;
NOTE: The ANYDTDTE. informat does not support this format before SAS version 9.4
If you cannot use the informat then read the value as three fields and convert it yourself.
input d $ m $ y $ ;
date = input(cats(d,substr(m,1,3),y),date9.);
Not sure why Tom's solution doesn't work on your machine... Here's another possibility:
data mydates;
infile datalines dsd truncover delimiter=" ";
informat day 8.
month $3.
year 8.;
format mydate date9.;
input day month year;
mydate = input(cats(day, month, year),date9.);
datalines;
20 march 2016
18 december 16
;
Related
I have this dataset and i would like to read it. I still encounter some error. May I know how would i be able to solve them?
data ThreeDates;
infile datalines;
input Date1 ddmmmyy10. Date2 ddmmyy10. Date ddmmyy9.;
datalines;
01/03/1950 01/03/1960 03Jan1970
05/15/2000 05/15/2002 15May2003
10/10/1998 11/12/2000 25Dec2005
;
run;
You need to add a : modifier to read non-standard data. It specifies an informat that the INPUT statement uses to read the variable value. The purpose is to read data values that need the additional instructions that informats can provide but that are not aligned in columns. If data was aligned in columns, you would use #n (line pointer controls).
You should also use the date9. informat for the Date column.
data ThreeDates;
infile datalines;
input Date1 :mmddyy10. Date2 :mmddyy10. Date :date9.;
format date: mmddyy10.;
datalines;
01/03/1950 01/03/1960 03Jan1970
05/15/2000 05/15/2002 15May2003
10/10/1998 11/12/2000 25Dec2005
;
run;
More information about lists in INPUT Statement.
PS: Instead of the : modifier, you could also use the INFORMAT statement before the INPUT statement:
data ThreeDates;
infile datalines;
informat date1-date2 mmddyy10. date date9.;
input Date1 Date2 Date;
format date: mmddyy10.;
datalines;
01/03/1950 01/03/1960 03Jan1970
05/15/2000 05/15/2002 15May2003
10/10/1998 11/12/2000 25Dec2005
;
run;
I have a column called month as
month
JAN
FEB
...
DEC
I'd like to know how to convert them into 1,2,3,...,12 in SAS. Thanks a lot.
Use informat to convert it to number and use month() to get the month.
data have;
input month :$3. ##;
datalines;
JAN FEB DEC
;
data want;
set have;
x=month(input(month||'21',??monyy.));
run;
Concatenate the month with a year, make use of the MONYY. informat, use the MONTH. format and finally output as a numeric value using another input().
data have;
input month :$3. ##;
datalines;
JAN FEB DEC
;
data want;
set have;
month_num=input(put(input(catt(month, year(today())), monyy.), month.), 2.);
put month month_num;
run;
Results:
JAN 1
FEB 2
DEC 12
I am trying to create a SAS informat for the following date format:
"yyyy-mm-dd hh:ii:ss.SSS UTC", example: "2016-01-14 10:31:01.456 UTC"
I've gotten close using the following format code:
PROC FORMAT;
PICTURE MyDate other='%0Y-%0m-%0d %0H:%0M:%0s UTC' (datatype=datetime);
RUN;
Unfortunately when I try and use this as an INFORMAT I get an error "can't find format MyDate", as it hasn't been defined as an informat, just an output format.
I can try and create an informat from a dataset created from this format, but due to the milliseconds constraint it will only create values that map to times with .000 in the milliseconds section. For example:
DATA MyInDate ;
RETAIN FMTNAME "MyInputDate" type "I" ;
do label = "1jan2016:00:00:00"dt to
"2feb2016:00:00:00"dt by 1;
start = trim(left(put(label,MyDate.)));
output ;
end ;
RUN;
PROC FORMAT CNTLIN=MyInDate;
RUN;
Even if I were able to enumerate a dataset with milliseconds it would be prohibitively large. Since my dates can span years.
Is it possible to truncate my input data BEFORE passing it to the informat? I don't care about the milliseconds or the UTC qualifier. I can't change the input data.
EDIT: Using anydtdtm. as an informat results in empty values without error messages. Here is the data step making use of this informat:
DATA WORK.ImportDatTest;
LENGTH
'Event Time'n 8
;
FORMAT
'Event Time'n DATETIME25.
;
INFORMAT
'Event Time'n anydtdtm.
;
INFILE DATALINES DLM=','
;
INPUT
'Event Time'n : ANYDTDTM.
;
DATALINES;
2016-01-11 17:23:34.834 UTC
2016-01-11 17:23:34.834 UTC
2016-01-11 17:23:34.834 UTC
;
RUN;
Unfortunately, there is no way to create a picture informat in SAS currently. You would need to convert your data to a format SAS has a built-in informat for, or use a function or similar to format the data.
However, yours already is in such a format, so you shouldn't need to create an informat.
data test;
x="2015-10-05 10:12:24.333 UTC";
y=input(x,anydtdtm.);
put y= datetime17.;
run;
You can certainly truncate data while using an informat; by specifying a length in the informat, it will truncate to that length.
Here's an example using input from datalines:
data test;
infile datalines dlm=',' dsd;
input y :anydtdtm32.;
put y= datetime22.3;
datalines;
2015-10-05 10:12:24.333 UTC
2014-03-01 08:08:05.435 UTC
2013-01-01 23:02:05.445 UTC
;;;
run;
My datalines has 2 variables, date 1 and date 2 with corresponding format ddmmyy10. and mmddyy10.
data date;
input date1 ddmmyy10. date2 mmddyy10.;
datalines;
09/01/2015 01/09/2015
10/01/2015 01/10/2015
11/01/2015 01/11/2015
12/01/2015 01/12/2015
13/01/2015 01/13/2015
;
run;
I tried to add the code but still not work
infile datalines delimiter=' ';
The : (colon) format modifier enables you to use list input but also to specify an informat after a variable name, whether character or numeric. SAS reads until it encounters a blank column, the defined length of the variable (character only), or the end of the data line, whichever comes first.
Format Modifier
data date;
input date1: ddmmyy10. date2: mmddyy10.;
datalines;
09/01/2015 01/09/2015
10/01/2015 01/10/2015
11/01/2015 01/11/2015
12/01/2015 01/12/2015
13/01/2015 01/13/2015
;
run;
The reason why the code is not working is because you are using List input to read non-standard data without colon input modifier or informat statement.
For non-standard data(commas, dollar, date etc. -> Reading Raw data -> Kinds of Data ) or standard data of length greater than 8 byte using List input technique you would need to use either INFORMAT statement or colon modifier with INPUT statement.
1) Assign informat for the input variables using INFORMAT statement or ATTRIB statement
data date;
informat date1 ddmmyy10. date2 mmddyy10.;
input date1 date2;
format date1-date2 yymmdd10.;
datalines;
09/01/2015 01/09/2015
10/01/2015 01/10/2015
;
run;
2) Use Colon (:) input modifier
data date;
input date1: ddmmyy10. date2: mmddyy10.;
format date1-date2 yymmdd10.;
datalines;
09/01/2015 01/09/2015
10/01/2015 01/10/2015
;
run;
I have data in csv format with a certain timestamp field in this format:
' 2009-07-30 20:50:19'
How can I read that into a SS dataset? Ive been trying this, but to no avail.
data filecontents;
infile "C:\es.txt" dlm=',' MISSOVER DSD firstobs=2 lrecl=32767 ;
input START_TIME :ANYDTDTM.
FORMAT START_TIME datetime.
Thanks.
Seems fine to me. The below code works on my machine (9.3 TSM2). What happens for you? Are you just missing a semicolon after the input statement (your example code is)?
data test;
infile "c:\temp\test.csv" dlm=',' missover;
input
dtvar :YMDDTTM.
var1 $
var2 $;
format dtvar DATETIME19.;
put dtvar= DATETIME19.;
run;
result:
608 data test;
609 infile "c:\temp\test.csv" dlm=',' missover;
610 input
611 dtvar :YMDDTTM.
612 var1 $
613 var2 $;
614 format dtvar DATETIME19.;
615 put dtvar= DATETIME19.;
616 run;
NOTE: The infile "c:\temp\test.csv" is:
Filename=c:\temp\test.csv,
RECFM=V,LRECL=256,File Size (bytes)=31,
Last Modified=20Nov2012:20:20:51,
Create Time=20Nov2012:20:17:51
dtvar=30JUL2009:20:50:19
NOTE: 1 record was read from the infile "c:\temp\test.csv".
The minimum record length was 29.
The maximum record length was 29.
NOTE: The data set WORK.TEST has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds
For what it's worth, YMDDTTMw.d is the specific informat for that (ANYDTDTM. will work as well of course).