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

I have a variable called date that's in the format yymmdd10., and I need to convert it in a numeric value, for example: 2022-04-18 will be converted into 20220418 (or look different, as long as it's a number) as a numeric variable.

 

I have tried this code but it doesn't work. the output variable n is all empty.

 

DATA want;
SET have;

n=input(put(date, yymmdd10.), 8.);
put n=;
RUN;

 

appreciate the help! 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Just change the format to

 

yymmddn8.

 

This changes the appearance. If you really need to change the underlying value, then try

 

data want;
     date='18APR2022'd;
     new_date=vvalue(date);
     format date yymmddn8.;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Just change the format to

 

yymmddn8.

 

This changes the appearance. If you really need to change the underlying value, then try

 

data want;
     date='18APR2022'd;
     new_date=vvalue(date);
     format date yymmddn8.;
run;
--
Paige Miller
Michael_Harper
Obsidian | Level 7

I created your "have" dataset.

 

data have;
input date $10.;
datalines;
2022-04-18
run;

DATA want;
format n yymmdd10.;
SET have;

n=input(date, yymmdd10.);
put n= ;
RUN;

Michael Joe Harper

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 1492 views
  • 3 likes
  • 3 in conversation