hello
I want to transform date format to year
data _7_Morningstar_Data2_expense;
set _7_Morningstar_Data_expense;
sas_date = input(put(date, 40.), YEAR.);
format sas_date YEAR.;
run;
@sasphd wrote:
no date is $40. format is not a date in SAS file I want to transform it to date format and it is in year like 1984; 1985 etc
A date format would imply there is a year, month and day; but if you only have year, then just leave it as an integer. No formatting needed.
sas_date = put(strip(date), 4.);
Is variable DATE a true SAS date value? If so, all you need to do is assign format YEAR. to this variable.
What is the variable type and format according to PROC CONTENTS? Is it numeric? Or is it character? What format does it have? What are typical values?
no date is $40. format is not a date in SAS file I want to transform it to date format and it is in year like 1984; 1985 etc
@sasphd wrote:
no date is $40. format is not a date in SAS file I want to transform it to date format and it is in year like 1984; 1985 etc
A date format would imply there is a year, month and day; but if you only have year, then just leave it as an integer. No formatting needed.
sas_date = put(strip(date), 4.);
So you have character variable that could have string up to 40 bytes long?
And you want to convert that into a number that represents a year?
Hopefully most of the values do not contain strings that are longer than 4 characters otherwise I am not sure what a year that large would mean.
The INPUT() function is what you need to convert character strings into numbers. The maximum length the numeric informat can handle is 32 bytes.
year=input(left(date),32.);
If you want to treat that as an actual date then you will need to pick some specific day within that year, such as January first.
If you want to display just the year from this calculated date value you could attach the YEAR format to it.
sas_date=mdy(1,1,year);
format sas_date year4.;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: