SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
branbran
Calcite | Level 5


Hi I'm trying to create a new variable using a month and year variable. I believe I should use the format Monyy7. but I am not sure what function to use. Typically I would use MDY ( Month, Day, Year).... but I do not have the day so I am a bit stumpped especially since MY (Month, year) does not work. See the example below....

data female;                                                                       data female;

date = MDY (Month, day, year);    -------->                          ????date = MY (month, year)?????

format Date monyy7.;                                                          format Date monyy7.;

run;                                                                                    run;

Please help!!!

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

In case of this, you will have to artificially plug in a day number: data=mdy(month,1,year).

Haikuo

Update: more clarification: if you let SAS to choose base on your limited information, SAS will pick the first day of the month:

data _null_;

month=7; year=2012;

date1=input(catx('-',month,year),ANYDTDTE.);

date2=mdy(month,1,year);

put "date1=" date1 date9. "  date2=" date2 date9.;

run;

View solution in original post

5 REPLIES 5
Haikuo
Onyx | Level 15

In case of this, you will have to artificially plug in a day number: data=mdy(month,1,year).

Haikuo

Update: more clarification: if you let SAS to choose base on your limited information, SAS will pick the first day of the month:

data _null_;

month=7; year=2012;

date1=input(catx('-',month,year),ANYDTDTE.);

date2=mdy(month,1,year);

put "date1=" date1 date9. "  date2=" date2 date9.;

run;

Josie1
Obsidian | Level 7

this is the exact problem i am having now except I want sas to choose the end of the month. Im working with gdp time series data that is the total for the month at the end of the month. I plan to put them into proc expand to get them to daily and calculate a moving average so if sas assumes the 1st day that will mess me up. why cant they do date=my(month,year) ? i tried exactly what the original poster tried bc that would have been so logical 😕

Josie1
Obsidian | Level 7

nevermind. your original solution looks like it works for me instead of data9. format i used yymmn6.

PatrickCuba
Obsidian | Level 7
What day?
Just use 1
Every month has 1
Pun intended
Josie1
Obsidian | Level 7
I got it to give me the dates in YYYYMM using the original solution that was there. But Im using a gdp data series where the observations represent the total at the end of the month. Im trying to convert from end of month monthly observations to daily in proc expand now that I have them in the right format

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 39918 views
  • 0 likes
  • 4 in conversation