Help using Base SAS procedures

Please help me to create sas date

Reply
Occasional Contributor
Posts: 15

Please help me to create sas date

Hi All,

I have a date in MMDDYY6. format such as 122905.
I want to create a date only with month and year such as 1205. What is the correct format to use? I tried using MONYY.w but it is not working. Can any one please help me out?

Thanks
SAS Super FREQ
Posts: 8,743

Re: Please help me to create sas date

Hi,
A bit more information is needed. You say that you "have a date" -- is your date column -already- in a SAS dataset? Could it be in a CSV file, or some other file (like a database file) and you want to READ it into SAS date format? Like this example of CSV:
[pre]
"Name","Bday","Idea"
"Alan",122905,"Books"
"Barb",111550,"CDs"
[/pre]

If your date value is in a SAS dataset, is it a numeric variable or a character variable? (You can figure this out by running PROC CONTENTS). Does it have a SAS date format assigned already (also PROC CONTENTS).

If your date variable is actually a character string, then you have to convert it from character to numeric form in order to use the MONYY format.

What do you see when you do a PROC PRINT of the data? Can you read the numbers or do they look strange? (For example 122905 stored as a SAS date value will show up unformatted in the data as: 16799 because December 29, 2005 was 16799 days after January 1, 1960).

In order to help you, we need some idea of what you're dealing with -- raw data or data that's already in a SAS dataset or data that's coming from a relational database. Whether your date value is "raw" or is already stored as a SAS date value or is a character string that represents the date. How (what procedure) you are using to apply the MONYY format.

cynthia
Occasional Contributor
Posts: 15

Re: Please help me to create sas date

Hi Cynthia

Sorry for being late.

Here are the answer for your question.

The date column is already in a SAS dataset. It is in MMDDYY6. format and it is a numeric variable.

Here is what I want to do:

1. I have a date column in a SAS dataset like:
120508 (MMDDYY6. format datatype numeric).
2. I want to extract only month and year as a date format like:
1208.
3. I want to subset dataset using this mmyy with if statement like
if data >=1205 then output sas-dataset.

I am using SAS 9.1 version. I read somewhere that SAS 9.1 has bug when you use MONYY format.

Thanks
N/A
Posts: 0

Re: Please help me to create sas date

Could you do something like this:

data test2;
set test;
if date ge mdy( 12, 1, 2005 ) then output;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: Please help me to create sas date

Regarding MONYY format, you would not be able to test against this "formatted" value using any value other than equal-to, since the formatted value is going to be "mmm" and "yy" where "mmm" is the character-name month value and not a number. I suppose that until the year 2100, you could use formatted value for mmyyn4. or yymmn4. to check for > (greater than).

It would be best to use the MDY function as suggested so that any comparison is against the numeric (SAS internal) value, representing days since 1/1/1960.

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,743

Re: Please help me to create sas date

Hi:
Remember that the formatted value is not relevant or doesn't come into play when you do comparisons. So, these are all equivalent:
[pre]
if birthday = -3334 then output;
if birthday = '15nov50'd then output;
if month(birthday) = 11 and year(birthday) = 1950 and
day(birthday) = 15 then output;
if birthday=mdy(11,15,1950) then output;
[/pre]

So if you wanted -everybody- born in November 1950, you cannot have:
[pre]
if birthday = 1150 then output;
but, instead would need:
if month(birthday) =11 and year(birthday) = 1950 then output;
[/pre]

cynthia
Ask a Question
Discussion stats
  • 5 replies
  • 159 views
  • 0 likes
  • 4 in conversation