DATA Step, Macro, Functions and more

Format problem

Reply
Occasional Contributor
Posts: 5

Format problem

Hello,

 

I've got a problem using the format statement on date. I do:

data projet.test;
INFILE "X:/Projet SAS/data1.txt" firstobs=2 dlm="09"x;
input date_diagnostic : DDMMYY10. date_ex : DDMMYY10. EPL$;
run;


data projet.test;
FORMAT date_diagnostic DATE9. date_examen DATE9.;
run;

proc print data= projet.test;
run;

But the format of the date does not change when i do that and i have to do:

data projet.test;
INFILE "X:/Projet SAS/data1.txt" firstobs=2 dlm="09"x;
input date_diagnostic : DDMMYY10. date_ex : DDMMYY10. EPL$;
FORMAT date_diagnostic DATE9. date_examen DATE9.;
run;

proc print data= projet.test;
run;

To make it work.

 

Do you know what is wrong ?

Thank you

 

SAS Super FREQ
Posts: 496

Re: Format problem

[ Edited ]
Posted in reply to prehendere

You answered your own question.  Do it in one step.  If you insist on doing it in two steps, add a SET statement.

data projet.test;
INFILE "X:/Projet SAS/data1.txt" firstobs=2 dlm="09"x;
input date_diagnostic : DDMMYY10. date_ex : DDMMYY10. EPL$;
run;


data projet.test;
set projet.text; FORMAT date_diagnostic DATE9. date_examen DATE9.; run;

 

Super User
Posts: 22,874

Re: Format problem

Posted in reply to prehendere

The format statement can be applied in most PROCS and you can change it on the fly if desired. 

As noted by @WarrenKuhfeld the problem in your first set of code is that you forgot to include the SET statement. 

This means that you effectively destroyed your TEST data set and in fact, you would have other issues besides just a missing format. 

 

 

data projet.test;
INFILE "X:/Projet SAS/data1.txt" firstobs=2 dlm="09"x;
input date_diagnostic : DDMMYY10. date_ex : DDMMYY10. EPL$;
FORMAT date_diagnostic DATE9. date_examen DATE9.;
run;

proc print data= projet.test;
format date_diagnostic mmddyy10. date_examen yearmon7.;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 270 views
  • 0 likes
  • 3 in conversation