BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
munitech4u
Quartz | Level 8

I have imported an input file, which has date in the form:

20.06.2011

Most of the fields are empty which read like '"-".

how do i get the date out of such format, its currently read in character format

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  You did not explain how you are doing the import (PROC IMPORT, DATA step program) or what your original file is (Excel, text file, CSV, etc).

                

  When you say that "most of the fields are empty" -- usually, SAS would read "empty" fields as missing numeric (a single dot) or missing character (a single space). So a hyphen or dash for missing is odd.

         

  But, if your date is a character string and you want to create a numeric variable with a date value (number of days since Jan 1, 1960), then the INPUT function is what you need to use. For example, let's assume that your character variable was called CHARDATE and that it had a text string of 15.11.1950 (which you wanted to convert to the number -3334, which represents a SAS date value for Nov 15, 1950). Then you would use the INPUT function like this (in a program):

newdatevar= input(chardate,anydtdte10.);

altdatevar = input(chardate,ddmmyy10.);

       
  Where ANYDTDTE or DDMMYY are the "informats" that you need to use to convert your character string INTO a SAS date value with the INPUT function. But if you are using a DATA step program to read your data in the first place, it might be easier to read the data in an INPUT statement like this:

INPUT numvar : anydtdte. ;

  But whichever method you use, you will need an INFORMAT such as ANYDTDTE or DDMMYY in order to read or convert the date value correctly.

     

  Then, the value for the variables would be -3334, internally, and if you wanted to see them as meaningful dates, you would use a SAS format statement like this:

format newdatevar altdatevar mmddyy10.;

           
cynthia

View solution in original post

2 REPLIES 2
Reeza
Super User

The ddmmyy informat will read this appropriately and specify missing for those that aren't.

How have you specified your informat for this variable?

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

DDMMYYw. Informat

Reads date values in the form ddmmyy<yy> or dd-mm-yy<yy>, where a special character, such as a hyphen (-), period (.), or slash (/), separates the day, month, and year; the year can be either 2 or 4 digits.
Cynthia_sas
SAS Super FREQ

Hi:

  You did not explain how you are doing the import (PROC IMPORT, DATA step program) or what your original file is (Excel, text file, CSV, etc).

                

  When you say that "most of the fields are empty" -- usually, SAS would read "empty" fields as missing numeric (a single dot) or missing character (a single space). So a hyphen or dash for missing is odd.

         

  But, if your date is a character string and you want to create a numeric variable with a date value (number of days since Jan 1, 1960), then the INPUT function is what you need to use. For example, let's assume that your character variable was called CHARDATE and that it had a text string of 15.11.1950 (which you wanted to convert to the number -3334, which represents a SAS date value for Nov 15, 1950). Then you would use the INPUT function like this (in a program):

newdatevar= input(chardate,anydtdte10.);

altdatevar = input(chardate,ddmmyy10.);

       
  Where ANYDTDTE or DDMMYY are the "informats" that you need to use to convert your character string INTO a SAS date value with the INPUT function. But if you are using a DATA step program to read your data in the first place, it might be easier to read the data in an INPUT statement like this:

INPUT numvar : anydtdte. ;

  But whichever method you use, you will need an INFORMAT such as ANYDTDTE or DDMMYY in order to read or convert the date value correctly.

     

  Then, the value for the variables would be -3334, internally, and if you wanted to see them as meaningful dates, you would use a SAS format statement like this:

format newdatevar altdatevar mmddyy10.;

           
cynthia

sas-innovate-2024.png

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.

 

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
  • 5991 views
  • 0 likes
  • 3 in conversation