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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2414 views
  • 3 likes
  • 3 in conversation