BookmarkSubscribeRSS Feed
prehendere
Calcite | Level 5

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

 

2 REPLIES 2
WarrenKuhfeld
Ammonite | Level 13

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;

 

Reeza
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1313 views
  • 0 likes
  • 3 in conversation