Hi All,
I've found a lot of posts almost aswering question but so far nothing addressing it directly:
I have a character date variable called "mthdate" that is formatted like this YYYY-MM (eg. 2015-05)
Is there a straightforward way to transform this into a SAS date? Since I don't have the days in the dataset we can assume that 2015-05 is the first of the month (eg. 2015-05-01)
any thoughts are always much appreciated.
Thank you.
Mike
data h;
input date $10.;
cards;
2015-05
;
data w;
set h;
new_date=input(date, anydtdte21.);
format new_date yymmdd10.;
run;
data h;
input date $10.;
cards;
2015-05
;
data w;
set h;
new_date=input(date, anydtdte21.);
format new_date yymmdd10.;
run;
That did the trick. Thank you.
Is there a way to get it to display as just the SAS date #"
eg. April 1 2011 = 18718
Thanks again.
Mike
do you mean without any format just as numbers or some other format?
Just as numbers I think.
Here's the context:
Essentially I have panel data with 1 record per person in my study for each month of the study (study is 5 years so 60 records per individual).
The challenge that I am running into is that the "age" variable I was given is calculated as the persons age at the beginning of the study, and it is static (so if someone is 18 at the beginning of the study, the the value of "age" is 18 in all 60 records, even though they clearly aren't 18 after the first year.)
I need to keep as many records as possible, so I'm hoping to generate a new variable that will update the given "age variable" every month. Also, because I don't actually know the birthdays of my participants, for the purposes of creating this variable, everyone's birthday is July 2nd. So on July 2nd everyone gets a year older.
It's a bigger question than I originally asked, but I thought the broader context might be helpful. If you care to offer any potential solutions I'd be eternally grateful.
I'm not sure if that's enough info, happy to give you anything else you need.
Mike
Basically, a sas date is a numeric date and a format merely is a display of the numeric date. So there is no change in the date value(number) regardless of what format you apply,
If you just want to display as numbers, simply do not apply a format, nonetheless this does;t change anything.
remove this
format new_date yymmdd10.;
from the program.
Anyways, for your bigger challenge, I would request you to please open up a new thread with a comprehensive input sample data with an expected output sample data and of course with a words explaining the business logic. This will help res-ponders to take a stab at it.
Feel free to post any number of questions no matter how complex you deem it to be. That;s what the forum is for. All fun.
Thanks so much Novino, both for your help on this one and the suggestion to start a new post for the larger problem.
I've started a new thread over here:
Thanks again.
Mike
Yes sir, saw that will be on it in a bit. I am sure that helps other SAS champs too. Just an idea to make it convenient. Thanks so much!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.