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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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