dates vary in length. single digit months and single digit days do not have leading zeroes.
WHENCREATED
9/20/2018 7:58 AM
9/2/2018 7:00 AM
11/20/2018 9:58 AM
data WORK.CHRONIC_ABSENTEEISM;
infile 'G:\FAKEPATH\Chronic_Absenteeism.csv' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat WHENCREATED ???;
format SchoolYear 4. CollectionID $4. DISTRICTCODE 4.;
input SchoolYear CollectionID $ DISTRICTCODE WHENCREATED;
run;
Use the mdyampm informat, as suggested by @andreas_lds, and a proper datetime format for display:
data want;
infile cards dlm=',' truncover;
input
schoolyear :4.
collectionid :$4.
districtcode :$4.
whencreated :mdyampm25.
;
format whencreated e8601dt20.;
cards;
2018,AAAA,AAAA,9/20/2018 7:58 AM
2018,BBBB,BBBB,9/2/2018 7:00 AM
2018,CCCC,CCCC,11/20/2018 9:58 AM
;
run;
Do you want a date or datetime? They are different.
Unless you have reason to suspect that you have incomplete or partial dates you might try ANYDTDTM32.
Assign a datetime19. or longer format to display a 4 digit year.
Hello Sir,
Good Morning !!
Thank you for your suggestion on above question . I applied informat and format as mention. But while applying format datetime20. or datetime19. , view of date & time got change. if i applied only any date format then it's working perfectly.
Here is my code.
data test;
input date anydtdte32.;
format date datetime20.;
cards;
9/20/2018 7:58 AM
9/2/2018 7:00 AM
11/20/2018 9:58 AM
;
run;
here is output . Looking for your suggestion .
You have a date and not a datetime.
Use
format date date9.;
Try mdyampm20. as informat, instead of anydtdte32.
You are using WRONG informat .
input date anydtdtm32.;
I don't get an error when using anydtdtm32.; but it returns all values as missing.
@singhsahab wrote:
Hello Sir,
Good Morning !!
Thank you for your suggestion on above question . I applied informat and format as mention. But while applying format datetime20. or datetime19. , view of date & time got change. if i applied only any date format then it's working perfectly.
Here is my code.
data test;
input date anydtdte32.;
format date datetime20.;
cards;
9/20/2018 7:58 AM
9/2/2018 7:00 AM
11/20/2018 9:58 AM
;
run;
here is output . Looking for your suggestion .
I suggested ANYDTDTM32 and expected to be reading from an external file. Your input would be incorrect in data lines as you are not accounting for spaces
data test; infile datalines dsd; input date anydtdtm32.; format date datetime20.; cards; 9/20/2018 7:58 AM 9/2/2018 7:00 AM 11/20/2018 9:58 AM ; run;
Use the mdyampm informat, as suggested by @andreas_lds, and a proper datetime format for display:
data want;
infile cards dlm=',' truncover;
input
schoolyear :4.
collectionid :$4.
districtcode :$4.
whencreated :mdyampm25.
;
format whencreated e8601dt20.;
cards;
2018,AAAA,AAAA,9/20/2018 7:58 AM
2018,BBBB,BBBB,9/2/2018 7:00 AM
2018,CCCC,CCCC,11/20/2018 9:58 AM
;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.