So here is my code. I'm following what my professors says to a T, but for some reason, I cannot convert date. It just wont work. The raw format is 12DEC2000 or Date9, in im correct. For some reason, the code I have below won't let me convert it.
data work.sanfran;
Infile '/folders/myfolders/sasuser.v94/Data for Classes 3 to 6/sfosch.dat';
Input @1 FlightID $7.
@8 RouteID $7.
@15 Destination $6.
@31 Model $6.
@40 Date $date9.
@64 TotPassCap 4.;
run;
proc print data=work.sanfran;
Format date $ddmmyy10.; /* THIS SHOULD BE WORKING*/
run;
Please do ALWAYS
(as in ALWAYS)
use the indicated button for posting logs, otherwise the horizontal formatting is destroyed and the log becomes mostly useless.
Similarly, you can open the file with a text editor (like Windows Editor or Notepad++, NOT a word processor like MS Word) and copy/paste a few lines into a window opened with the same button. Or you change the filename extension to .txt and attach the file to your next post.
I suspect that the positions in the code do not match the positions in the file. But I can only tell for sure once I see the data as it is.
SAS dates are numeric variables and so require numeric INFORMATs and FORMATs You need to remove the dollar signs preceding your date formats:
data work.sanfran;
Infile '/folders/myfolders/sasuser.v94/Data for Classes 3 to 6/sfosch.dat';
Input @1 FlightID $7.
@8 RouteID $7.
@15 Destination $6.
@31 Model $6.
@40 Date date9.
@64 TotPassCap 4.;
run;
proc print data=work.sanfran;
Format date ddmmyy10.; /* THIS SHOULD BE WORKING*/
run;
Thanks a bunch for your reply. The problem is that it doesn't seem to want to do that for whatever reason. If I remove my dollar signs I get a warning message and an empty column in my results.
Please post the log from your data step. Include all the code, and if you get lots of "invalid data" messages, just a few of them will be enough.
Please use the indicated button to post the log text:
In that case you may need to adjust your INPUT statement because the date is probably being read from the wrong columns. Please post your complete SAS log as @Kurt_Bremser has asked.
Here is the log
Please do ALWAYS
(as in ALWAYS)
use the indicated button for posting logs, otherwise the horizontal formatting is destroyed and the log becomes mostly useless.
Similarly, you can open the file with a text editor (like Windows Editor or Notepad++, NOT a word processor like MS Word) and copy/paste a few lines into a window opened with the same button. Or you change the filename extension to .txt and attach the file to your next post.
I suspect that the positions in the code do not match the positions in the file. But I can only tell for sure once I see the data as it is.
Format date $ddmmyy10.; /* THIS SHOULD BE WORKING*/
This should positively NOT work, as there is no $DDMMYY format.
The existing format DDMMYY is for numeric values.
Similarly, there is no $DATE informat, which a quick look at your log will reveal:
data test;
input date $date9.;
datalines;
01jan1960
;
Log:
73 data test; 74 input date $date9.; _______ 485 NOTE 485-185: Informat $DATE was not found or could not be loaded. 75 datalines;
This, OTOH, will work:
data test;
input date date9.;
datalines;
01jan1960
;
proc print data=test;
format date ddmmyy10.;
run;
Log:
73 data test; 74 input date date9.; 75 datalines; NOTE: The data set WORK.TEST has 1 observations and 1 variables. NOTE: Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit): real time 0.00 seconds cpu time 0.00 seconds 77 ; 78 79 proc print data=test; 80 format date ddmmyy10.; 81 run; NOTE: There were 1 observations read from the data set WORK.TEST. NOTE: Verwendet wurde: PROZEDUR PRINT - (Gesamtverarbeitungszeit): real time 0.03 seconds cpu time 0.02 seconds
DATE is now read as a numeric SAS date value, and can be displayed with one of the many date-related numeric formats.
I recommend this:
About SAS Date, Time, and Datetime Values
for further reading.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.