On my txt file the data in position 1 is formatted as 20020408.(yyyymmdd)
I want to import the academic_date in the same format (yyyymmdd) but as a date value in sas. How can I do this?
DATA import_file;
INFILE "K:\DATA\academic.file18.txt"
INPUT
@1 ACADEMIC_DATE $8.;
RUN;
Use
yymmddn8.;
format
DATA import_file;
INFILE "K:\DATA\academic.file18.txt"
INPUT
@1 ACADEMIC_DATE yymmdd8.;
format ACADEMIC_DATE yymmddn8.;
RUN;
why aren't you importing aka reading the date with an informat yymmdd10.?
DATA import_file;
INFILE "K:\DATA\academic.file18.txt"
INPUT
@1 ACADEMIC_DATE yymmdd10..;
format ACADEMIC_DATE yymmdd10.;
RUN;
The data is 8 characters in length. When I use the yymmdd10. I get an error message "invalid data for academic_date in line 1-9."
Post samples of your data so that we can test from our end. Also post the required output you want
As the length is 8 characters I used yymmdd8 and the result is 02-04-08. How can I remove get it to read as 20020408? no dashes
Use
yymmddn8.;
format
DATA import_file;
INFILE "K:\DATA\academic.file18.txt"
INPUT
@1 ACADEMIC_DATE yymmdd8.;
format ACADEMIC_DATE yymmddn8.;
RUN;
That did it. Thank you.
@novinosrin How can I read in 2018 as a numeric date.
I've tried:
DATA import_file;
INFILE "K:\DATA\academic.file18.txt"
INPUT
@ 10 year year4.;
if the value is a number, it is considered standard data and so you do need a special instruction aka informat to read.
So in your example 2018 can be directly read as year value
data want;
input year;
cards;
2018
;
No need to supply any informat
Sure, that doesn't make a difference whether you read from txt or csv or whateever. If your value is 2018 which is a year value and if you have logic date and month values in the same txt file, you could use mdy function to compute a sas date and format it the way you want.
What date do you think you would want to assign to just 2018?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: