Given data:
Date Company
20150101 Comp1
20150201 Comp2
20140301 Comp3.....
Desired output:
YYYY MM DD Company
2015 01 01 Comp1
2015 02 01 Comp2
2014 03 01 Comp3.....
Its an excel file with 10000 data sets.
What code will transform the given data into desired output?
Do you already know how to get your Excel files into a SAS data set, or is that part of the question?
Do you want your new fields as numeric or character?
Hi
I know to get excel into sas. I want to know the codes in SAS that can give me the desired output.
I want a character as well as numeric conversion codes.
Thanks.
Whats the type (numeric/character) and format of the variable?
You can look at the YEAR/MONTH/DAY function in SAS if your variable is numeric with a date format.
PS. Why do you want to convert this? You can use all sorts of aggregation levels if you keep it as a SAS date.
Hi
Date value is numeric.
Whats the type (numeric/character) and format of the variable?
Its numeric date in YYYYMMDD format.
Then use the YEAR/MONTH/DAY function to extract the relevant components.
See the relevant documentation under Date & Time Category:
Well, I'm going to go out on a limb, and assume that the number within DATE is actually the 8-digit number that appears in your example (and not a SAS date). In that case:
length yyyy_c $ 4 mm_c dd_c $ 2;
date_c = put(date, 8.);
yyyy_c = date_c;
mm_c = substr(date_c, 5, 2);
dd_c = substr(date_c, 7, 2);
yyyy_n = input(yyyy_c, 4.);
mm_n = input(mm_c, 2.);
dd_n = input(dd_c, 2.);
If I'm wrong, and you actually have a SAS date stored within DATE, then use the suggestion about date functions.
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 25. 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.