Help using Base SAS procedures

The INFORMAT Clarification

Accepted Solution Solved
Reply
N/A
Posts: 1
Accepted Solution

The INFORMAT Clarification

data dates;

infile datalines;

input State $ Date;

if State='AP' then do;

informat Date ddmmyy10.;

end;

else if State='MP' then do;

informat Date date9.;

end;

datalines;

AP 12/12/2015

AP 13/01/2014

MP 12Dec2015

MP 13Dec2014

;

run;

When I execute the above code snippet, its only accessing the latest loop & showing the o/p.I am unable to see the date formats as desired for both the conditions. May I know where the mistake lies?


Accepted Solutions
Solution
‎05-17-2015 10:43 AM
Trusted Advisor
Posts: 1,195

Re: The INFORMAT Clarification

Use anydtdte informat for both condistions.

data dates;

infile datalines;

input State $ Date :anydtdte.;

format date date9.;

datalines;

AP 12/12/2015

AP 13/01/2014

MP 12Dec2015

MP 13Dec2014

;

run;

View solution in original post


All Replies
Solution
‎05-17-2015 10:43 AM
Trusted Advisor
Posts: 1,195

Re: The INFORMAT Clarification

Use anydtdte informat for both condistions.

data dates;

infile datalines;

input State $ Date :anydtdte.;

format date date9.;

datalines;

AP 12/12/2015

AP 13/01/2014

MP 12Dec2015

MP 13Dec2014

;

run;

Super Contributor
Posts: 251

Re: The INFORMAT Clarification

INFORMAT is a COMPILE TIME Statement. Hence, originally it was ddmmyy10 but later it is changed to DATE9. . At the EXECUTION TIME, the real INFORMAT is the one that came last namely, DATE9.

Check the CONTENTS of the dates data set:

proc contents data = dates;

run;

and see the inforamat with date9.

Super Contributor
Posts: 251

Re: The INFORMAT Clarification

Dear Poster

Look at the note:

If you post a question and someone replies with information that you can use, it's a good idea to mark their reply as either helpful or correct. That way, others who have the same question can quickly see which replies might be most useful for them. A helpful reply is on the right track, while a correct reply answered your question. Keep in mind that you and others get more status points for posting replies that are marked as helpful or correct!

When you click Correct Answer for one of the replies, the original question becomes marked answered and you see a clip of the correct answer in your original question.

To mark responses to your question, go to the question in the community, look for responses, and click Helpful Answer or Correct Answer for each response that fits.  If you want to undo a correct or helpful answer, simply click Unmark as Helpful or Unmark as Correct.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 216 views
  • 0 likes
  • 3 in conversation