SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GreggB
Pyrite | Level 9

 

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;	
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

8 REPLIES 8
ballardw
Super User

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.

singhsahab
Lapis Lazuli | Level 10

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 . 

 

Capture.PNG

ChrisNZ
Tourmaline | Level 20

You have a date and not a datetime.

Use 

format date date9.;

andreas_lds
Jade | Level 19

Try mdyampm20. as informat, instead of anydtdte32.

Ksharp
Super User

You  are using WRONG informat .

 

input date anydtdtm32.;

GreggB
Pyrite | Level 9

I don't get an error when using anydtdtm32.; but it returns all values as missing.

ballardw
Super User

@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 . 

 

Capture.PNG


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;
Kurt_Bremser
Super User

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;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1893 views
  • 0 likes
  • 7 in conversation