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

Hi,

I have the date1 value = 1978 i.e. all in 4 digits with informat and format of $64. I want to covert it to a numeric value with a format of year4.

 

First I tried:

data want;

 set have;

if date2=input(date1,$64);

format date2 year4.;

run;

 

It doesn't work.

 

If I remove the format statement it keeps the value as character as the original variable.

 

I also tried date2=input(date1, year4.); and that doesn't work too.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

you could assign a length to the date2 like this

 

data want;

length date2 4.;

 set have;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

There is no YEAR format or INFORMAT.

 

Years don't need formats, if the year is 1978, everyone knows what that means and you don't need to change its appearance with a format.

 

In your case, you want to simply convert from character to numeric

 

date2 = input(date1,4.);
--
Paige Miller
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

you could assign a length to the date2 like this

 

data want;

length date2 4.;

 set have;

dr2014
Quartz | Level 8

And will remember that.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 5662 views
  • 1 like
  • 3 in conversation