How to read a column from a text file as character value using proc import in SAS 9.4

Reply
Occasional Contributor
Posts: 10

How to read a column from a text file as character value using proc import in SAS 9.4

In SAS 9.2, when i read a text file using proc import to bring as a SAS dataset, one of the column which had date value [2015/08/13:12:00:00 AM] used to be imported as character format and the date value remained the same [2015/08/13:12:00:00 AM].

 

Now, in SAS 9.4 when i use the same proc import to import the same text file to SAS dataset, the column with the value [2015/08/13:12:00:00 AM] comes in as a date format with the value changed to 13AUG15:00:00:00. We just moved from 9.2 to 9.4.

Here is the code that was working for me in 9.2.

proc import datafile="C:\Desktop\Sample.txt"

out=test12

dbms=dlm

replace;

delimiter=',';

datarow=2;

run;

 

I tried to use the option usedate=no but SAS throws me an error.

Respected Advisor
Posts: 3,775

Re: How to read a column from a text file as character value using proc import in SAS 9.4

It looks like the change with 9.4 is to read the variable as DATE and format it with the default datetime format.  You can change the format to display to mdyampm using the format of the same name.

 

If you want character variable (not useful) you can PUT the data into a new variable using the MDYAMPM. format.

 

You could also modify the code generated by PROC IMPORT 

 

But why.  A datetime variable is much more useful that a character string of the same data.

Occasional Contributor
Posts: 10

Re: How to read a column from a text file as character value using proc import in SAS 9.4

Hi data_null_,

      The mdyampm format changes the value to  8/13/2015 12:00 AM from [2015/08/13:12:00:00 AM]. Now, the issue is i am pulling the year and month value from that column and with the new format there is no leading '0' in front of the single date value like '8'. i cannot use substring to pull those values, since the date value is either a single or double digit.

Is there a format to get the leading zero in the value such as 08/13/2015 12:00 AM instead of 8/13/2015 12:AM

 

Thanks

 

Grand Advisor
Posts: 10,229

Re: How to read a column from a text file as character value using proc import in SAS 9.4

If you are extracting values from a datetime variable then there are easy ways to do so:

 

Year = year(datepart(datetimevariablename));

Month = month(datepart(datetimevariablename));

Day = day(datepart(datetimevariablename));

 

Not to mention formats that will display the value as desired such as DTDATE, DTMONYY, DTWKDATX, DTYEAR, DTYYQC.

Respected Advisor
Posts: 3,775

Re: How to read a column from a text file as character value using proc import in SAS 9.4

As I mentioned and as @ballardw has demonstrated with and example, a DATETIME variable is much easier to work with than a character string.

Ask a Question
Discussion stats
  • 4 replies
  • 315 views
  • 0 likes
  • 3 in conversation