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
Rhodochrosite | Level 12

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;

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