BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

Why field var1  is numeric and not a sas date?

data a; 
infile cards;  
input var1 mmddyy10.;
cards; 
01/23/1963 
;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
heffo
Pyrite | Level 9

SAS dates are numeric, but most of the time they have a format. So, it is correct. 

data a;
	infile cards;
	format var1 yymmdd10.;
	input var1 mmddyy10.;
	cards;
01/23/1963 
;
run;

 

So, you are using an informat, to tell SAS how to translate the text "01/23/1963". Then SAS saves it as the number of days between that date and 1st of January 1960. Then, if you want to, you can add an "outformat" to make it more readable. 

 

Most software solutions saves dates in this way, but the start date is often different. Microsoft Excel use 1st of January 2000 (or 1900) as a start date.

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

SAS dates are numeric. They are the number of days since 01/01/1960. Add a date format to your variable to see it as a date:

 

format var1 yymmdd10.;

PG
Tom
Super User Tom
Super User

@Ronein wrote:

Hello

Why field var1  is numeric and not a sas date?

data a; 
infile cards;  
input var1 mmddyy10.;
cards; 
01/23/1963 
;
run;

 


VAR1 will be a date. It will be the number days since 1960. But since you didn't attach any format it will be confusing to humans, but not to SAS.  If you want to make it looks like a date to a human then attach a date format. Like DATE9. or YYMMDD10.

heffo
Pyrite | Level 9

SAS dates are numeric, but most of the time they have a format. So, it is correct. 

data a;
	infile cards;
	format var1 yymmdd10.;
	input var1 mmddyy10.;
	cards;
01/23/1963 
;
run;

 

So, you are using an informat, to tell SAS how to translate the text "01/23/1963". Then SAS saves it as the number of days between that date and 1st of January 1960. Then, if you want to, you can add an "outformat" to make it more readable. 

 

Most software solutions saves dates in this way, but the start date is often different. Microsoft Excel use 1st of January 2000 (or 1900) as a start date.

Kurt_Bremser
Super User

Once again, follow Maxim 1: Read the Documentation, in this case About SAS Date, Time, and Datetime Values, which is found in the Learning SAS Programming section under Concepts.

You will find that SAS dates are indeed numeric.

Given the number of your accumulated questions and posts, I am quite sure this has been covered already.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 640 views
  • 2 likes
  • 5 in conversation