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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Doc_Duke
Rhodochrosite | Level 12

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

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

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.

Doc_Duke
Rhodochrosite | Level 12

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

DocStocks
Calcite | Level 5

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!

Reeza
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 17402 views
  • 6 likes
  • 4 in conversation