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
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;
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.