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

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 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data h;
input date $10.;
cards;
2015-05
;

data w;
set h;
new_date=input(date, anydtdte21.);
format new_date yymmdd10.;
run;

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20
data h;
input date $10.;
cards;
2015-05
;

data w;
set h;
new_date=input(date, anydtdte21.);
format new_date yymmdd10.;
run;
righcoastmike
Quartz | Level 8

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 

 

 

novinosrin
Tourmaline | Level 20

do you mean without any format just as numbers or some other format?

righcoastmike
Quartz | Level 8

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

 

 

novinosrin
Tourmaline | Level 20

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.  

righcoastmike
Quartz | Level 8

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: 

 

https://communities.sas.com/t5/Base-SAS-Programming/Trying-to-create-a-dynamic-age-variable/m-p/4693...

 

Thanks again. 

 

Mike

novinosrin
Tourmaline | Level 20

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-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!

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.

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
  • 7 replies
  • 6760 views
  • 0 likes
  • 2 in conversation