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

Hi,

 

What informat shall I use to input a date in the form MM.YYYY (period as separator). Example: March 2016 is represented as 03.2016.

 

ANYDTDTE7. works when hyphen (-) or slash (/) are used as separators. Returns a missing value when period is used as a separtor.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

You can read an external file directly if you redefine the value to read on the fly, and add the missing day :

 

proc format;
  invalue mmyyp (default=10)
          's/(.{7})/01.\1/o' (regexpe)=[ddmmyy10.];
run;

data WANT;
  input DATE mmyyp.;
  putlog DATE= date9. ;
cards;
03.2016
run;

 DATE=01MAR2016

 

More examples about all valid SAS regular expressions, including their use in informats, by following this link:

 

View solution in original post

5 REPLIES 5
Astounding
PROC Star

Dates in SAS refer to a particular day.  If you have just the month and year (in any format), you first need to decide what day of the month to use in order to convert your data to a SAS date.

ShagilImam
Obsidian | Level 7

Hi,

Thanks for your reply. 

'Day' does not really matter; it can be taken as 01.

 

I just need to read a file which will have month and year for a particular event.

As I mentioned, ANYDTDTE7. works fine with hyphen or slash as separators, that is, the following code gives expected output as 10.2016

 

 

data _null_;
informat dte anydtdte7.;
format dte mmyyp7.;
input dte;
put dte;
datalines;

10/2016
;
run; 

 

Taking 10-2016 in place of 10/2016 also works; but unfortunately, my input will be as 10.2016, which gives a missing value as output. 

Astounding
PROC Star

In that case, you might have to work around the problem by reading as text then changing "." to "/":

 

input textvar $;

dte = input( translate(textvar, '/', '.'), anydtdte7.);

Shmuel
Garnet | Level 18

Just for the fun you may even do (code tested and is ok):

 

data test;

       input date best7.4;

       date = input('01'||put(date*10000,z6.),ddmmyy8.);

      format date ddmmyy10.;

datalines;

03.2017

11.2016

5.1999

; run;

ChrisNZ
Tourmaline | Level 20

You can read an external file directly if you redefine the value to read on the fly, and add the missing day :

 

proc format;
  invalue mmyyp (default=10)
          's/(.{7})/01.\1/o' (regexpe)=[ddmmyy10.];
run;

data WANT;
  input DATE mmyyp.;
  putlog DATE= date9. ;
cards;
03.2016
run;

 DATE=01MAR2016

 

More examples about all valid SAS regular expressions, including their use in informats, by following this link:

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 4023 views
  • 2 likes
  • 4 in conversation