I know this answer is out there, but what I find via Google is how to format when importing data that is not already in SAS form. I really can't force myself to read a 10 page PDF (man, SAS is longwinded) for such a simple problem.
Anyway, here are the contents of my data:
Alphabetic List of Variables and Attributes
# Variable Type Len Format Informat Label
1 BondCusip Char 8 $8. $8. BondCusip
9 BondPrice Num 8
2 CPN Num 8 CPN
4 CPN_FREQ Num 8 CPN_FREQ
7 Cvx Num 8
6 Date Num 8 MMDDYY10.
8 Dur Num 8
5 ISSUE_DT Char 21 $21. $21. ISSUE_DT
3 MATURITY Char 21 $21. $21. MATURITY
I need Issue_dt and maturity to be numeric and formatted as mmddyy10. Any help is always appreciated.
To convert a text date to numeric, use the INPUT function, as in
maturityD=INPUT(maturity, anydtdte21.);
anydtdte will read a variety of date and date-time formats and extract the date (only) part.
To add the format,
FORMAT maturityd mmddyy10.;
SAS cannot change a data type from character to numeric in place; you have to change the variable's name to do it.
Doc Muhlbaier
Duke
What does the data look like? From the size of the field, I would guess they contain datetime data.
Anyhow, what you have to do is create two new fields, probably using the input and datepart functions, the anydtdtmw informat, and a format statement. However, I'm hesitant to suggest specific code without seeing an example of the data the two fields contain.
To convert a text date to numeric, use the INPUT function, as in
maturityD=INPUT(maturity, anydtdte21.);
anydtdte will read a variety of date and date-time formats and extract the date (only) part.
To add the format,
FORMAT maturityd mmddyy10.;
SAS cannot change a data type from character to numeric in place; you have to change the variable's name to do it.
Doc Muhlbaier
Duke
So that's the key. I must create a new variable from the old. I'm so use to Excel that it makes me assume SAS will behave the same way. Thanks a ton!
You're trying to change the variable TYPE from CHAR to NUMERIC.
I'm also guessing that your Issue_DT and Maturity are date time fields not date based on the length of 21. The ideal solution is to fix this when you initially get the data and make sure it imports/downloads/reads properly.
To change it at this point you need to give an example of how it looks it the field, is it 03Aug2011 or or 03/08/11 9:54:00.0 ... or something of the sort.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.