BookmarkSubscribeRSS Feed
rookie72
Calcite | Level 5
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
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
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
rookie72
Calcite | Level 5
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
deleted_user
Not applicable
Could you do something like this:

data test2;
set test;
if date ge mdy( 12, 1, 2005 ) then output;
run;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Cynthia_sas
SAS Super FREQ
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

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 820 views
  • 0 likes
  • 4 in conversation