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

Hello:

 

I have the following codes by created someone else.   Could anyone let me know why use informat and format together?  Thanks.

 


data test;
	set test;
	array aa &numrvar;
 	do over aa;
  	aa=datepart(aa);
end;
	informat &NUMRVAR MMDDYY10.; 
	format &NUMRVAR MMDDYY10.; 
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Yes. 

A number of DBMS systems do not have a concept of a date (number of days) and just have a general datetime (or timestamp) data type.  So people store dates with either a constant time part (like midnight) or perhaps the system supports some metadata that tells it how precise the timestamp value is.

 

So that SAS code will convert the values form number of seconds to number of days and adjust the formats/informats to those more appropriate for a date value.

View solution in original post

6 REPLIES 6
Reeza
Super User

And DO OVER has been deprecated. 

When you see code like this, one of two things likely happened:

 

1. The original author didn't understand informats

2. At one point the data was being read from a text file and then the process change and code was updated, but this was left in. 

Tom
Super User Tom
Super User

An INFORMAT is instructions for converting text to values. A FORMAT is instructions for converting values to text.

 

You need the FORMAT statement so that the dates will display in a human readable way.  You do not need to attach the informats for this program since you are not using them anywhere.  But it doesn't hurt.  And since you are converting from DATETIME to DATE values you probably do want to at least remove whatever INFORMATs were previously attached to those variables.

informat &NUMRVAR ; 

The informats might be useful later if you want to add observations using FSEDIT for example.

Or if you want to use the dataset as a template for reading some raw data.  You need an informat SAS to read values like '10/17/2018' as a number and not just a string.

data new;
  if 0 then set test;
  infile 'newdata.csv' dsd truncover ;
  input (_all_) (+0);
run;

 

ybz12003
Rhodochrosite | Level 12

Based on your feedback, I found out the original code is like this.   Does this means that library RSV is outside source, therefore, informat is used for external file?

 

data ARI18_&tdate.;
	set RSV."18ARI"n;
	array aa &numrvar;
 	do over aa;
  	aa=datepart(aa);
end;
	informat &NUMRVAR MMDDYY10.; 
	format &NUMRVAR MMDDYY10.; 
run;
Tom
Super User Tom
Super User

Yes. 

A number of DBMS systems do not have a concept of a date (number of days) and just have a general datetime (or timestamp) data type.  So people store dates with either a constant time part (like midnight) or perhaps the system supports some metadata that tells it how precise the timestamp value is.

 

So that SAS code will convert the values form number of seconds to number of days and adjust the formats/informats to those more appropriate for a date value.

ybz12003
Rhodochrosite | Level 12

Thank you so much for all of your valuable information. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 688 views
  • 2 likes
  • 4 in conversation