BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasworker16
Calcite | Level 5
DATA child_birthday;
input subject name $ year  month  date ;
datalines;
1001 Thomas 2000 12 15
;
run; 

I want to create a new variables named as birthday_yyyymmdd from the variables year, month, and date.

For example, from the dateset, l want to create a variable 2001215.

I have tried 

 

data child_birthday;
birthday_yymmdd=substr(year,1,4)+substr(month,1,2)+substr(date,1,2);
run;

but I am not getting anything.

 

Any help or comment would be appreciated.

 

Maria. 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisBrooks
Ammonite | Level 13

The reason it's not working is that you've created year, month and date as numeric whereas substr only works on character variables. If you want to create a date from individual numeric values use the mdy function like this

 

data want;
	format birthday_yymmdd date9.;
	set child_birthday;
	birthday_yymmdd=mdy(month,date,year);
run;

View solution in original post

3 REPLIES 3
ChrisBrooks
Ammonite | Level 13

The reason it's not working is that you've created year, month and date as numeric whereas substr only works on character variables. If you want to create a date from individual numeric values use the mdy function like this

 

data want;
	format birthday_yymmdd date9.;
	set child_birthday;
	birthday_yymmdd=mdy(month,date,year);
run;
ShiroAmada
Lapis Lazuli | Level 10

Not sure if this is what you want to do.

 

Try this....

 

data WANT;
  set HAVE;
call symput=("DT_SUFFIX",cats("BIRTHDAY_",YEAR,MONTH,DATE));
BIRTHDAY_=MDY(MONTH,DATE,YEAR);
format birthday_ date9.;
run;


proc datasets lib=work;
  modify want;
  rename birthday_=&dt_suffix.;
run;
quit;

Hope this helps.

TarunKumar
Pyrite | Level 9

data want;
set child_birthday;
format birthday_yymmdd yymmdd10.;
birthday_yymmdd =mdy(month,date,year);
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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