Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Programming (https://www.askmehelpdesk.com/forumdisplay.php?f=437)
-   -   SAS code to Format decimal places and julian date (https://www.askmehelpdesk.com/showthread.php?t=182526)

  • Feb 10, 2008, 01:15 PM
    sdemas45
    SAS code to Format decimal places and julian date
    I am working with a data set that I would like to link with another data set. However, I need to do two thing before linking the two data set together. One is that I have a variable claim that I need to format. The variable has values 250, 5525 etc and I need to place a period to make it 2.50, 55.25, etc. What SAS code to use to make it two decimal places? Secondly, I have the date in julian format like January 20, 2008 in this format "20080120"and I would to change to 02/20/2008. What SAS code to use to accomplish these two formating so that I can link the data set? Thanks for any help.
  • Feb 12, 2008, 04:03 PM
    dan70m1
    Hi,

    Firstly you don't say what type your "claim" field is? Char/num? For the purpose of the example, I will assume the values of 250, 5525 are stored as numbers. To convert to floating point values, simply divide by 100! If they are stored as CHAR then use:

    x="250";
    y="5525";
    x2=input(x,best.)/100;
    y2=input(y,best.)/100;


    For your date question, I will assume that your value of "20080120" is stored as a character string. To convert this to a number, try :

    attrib dt format=mmddyy10.;
    z="20080120";
    dt=mdy(input(substr(z,5,2),2.),input(substr(z,7,2) ,2.),input(substr(z,1,4),4.));


    the attrib statement will format your date correctly as you specified.

    Hope this helps
    D
  • Sep 26, 2012, 01:53 AM
    pmk123
    For the first question,if the variable is num and when you simple divide by 100,it does not work..
    The zeros are missing at the end.

    For ex:
    250/100 gives you a 2.5 and not a 2.50

    Can anyone answe this question.

  • All times are GMT -7. The time now is 12:49 AM.