BookmarkSubscribeRSS Feed

Hi,

I have a variable 'Remaining months' but I want this in a year format within proc sql but unsure on how to do this, any ideas please?

example -

Remaining months 60

I want to display 5 years

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Simply divide by 12.

data have;

     remaining_months=60; output;

run;

proc sql;

     create table WANT as

     select     REMAINING_MONTHS,

                    strip(put(REMAINING_MONTHS / 12,best.))||" years" as YEARS

     from       HAVE;

quit;

Thanks,

How do I round it to display 2 years instead of  2.1666666667 years

RW9
Diamond | Level 26 RW9
Diamond | Level 26

With the round function?  Alternatively the floor (probably the best one for your scenario) or ceil functions depending on scenario.

To add, any SAS function can be used in a proc sql as long as you are not using pass-through (i.e. sending the sql to a database) as the DB wouldn't know about the SAS functions).  In general though there are several of the functions which are present in both SAS and native SQL, round being one of them, though slightly different syntax.

http://www.w3schools.com/sql/sql_func_round.asp

SQL Functions

jakarman
Barite | Level 11

Using a 5.2 format for years instead of best.   - The best in this case is not your best. The best is showing as much as possible could make sense. 

---->-- ja karman --<-----
Hima
Obsidian | Level 7

DATA HAVE;
REMAINING_MONTHS=62;
OUTPUT;
RUN;

PROC SQL;
CREATE TABLE WANT AS
  SELECT     REMAINING_MONTHS,CATS((REMAINING_MONTHS / 12), "YEARS") AS YEARS FROM HAVE;
QUIT;

PROC PRINT;
RUN;

Capture.JPG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 5 replies
  • 573 views
  • 0 likes
  • 4 in conversation