Help using Base SAS procedures

Calculate Age and filter data

Reply
Occasional Contributor
Posts: 9

Calculate Age and filter data

[ Edited ]

Hi to all,

i have a problem with this:

The dataset initial is below:

ASSET TIPE DOB VEHICLE_AGE VEHICLE COST REG_DATE SNAPSHOT_DATE TERM
NEW 10/09/81 0 15000 01/03/14 01/04/14 12
USED 15/08/86 6 10000 01/09/13 01/04/14 12
NEW 26/11/92 0 20000 01/03/14 01/04/14 24
USED 17/02/95 18 5000 01/09/12 01/04/14 36

 

 

CAN YOU TELL ME WHAT IS A SAS DATASTEP WHICH CAN BE USED TO FIND THE AGE (IN WHOLE YEARS) FOR THE CUSTOMERS OF THE NEW VEHICLES AS AT SNAPSHOT_DATE.?

AND WHAT IS A SAS DATASTEP CAN BE USED TO FIND THE CONTRACT END DATE OF THE VEHICLE WITH TERM =36, ASSUMING THE VEHICLE WAS PURCHASED ON THE SNAPSHOT_DATE?

 

I THINK THAT THE CORRECT ANSWER IS: 

SELECT

ADD_MONTHS(SNAPSHOTDATE,36)

FROM'INITIAL DATA'

WHERE TERM=36

Occasional Contributor
Posts: 9

SAS

Hi to all,

i have a problem with this:

The dataset initial is below:

ASSET TIPEDOBVEHICLE_AGEVEHICLE COSTREG_DATESNAPSHOT_DATETERM
NEW10/09/8101500001/03/1401/04/1412
USED15/08/8661000001/09/1301/04/1412
NEW26/11/9202000001/03/1401/04/1424
USED17/02/9518500001/09/1201/04/1436

 

 

CAN YOU TELL ME WHAT IS THE MEAN FOT THE DOWNPAYMENT VARIABLE BELOW?

 

DOWNPAYMENT

10

.

2

0

 

PROC Star
Posts: 1,283

Re: SAS

I dont see the DOWNPAYMENT variable in the initial data set?

 

you can calculate the mean of DOWNPAYMENT like this

 

data have;
input DOWNPAYMENT;
datalines;
10
.
2
0
;

proc means data=have mean;
	var DOWNPAYMENT;
run;
Super User
Super User
Posts: 9,599

Re: SAS

Hi,

 

Avoid writing in capitals it is not plesant to read.  To answer your questions:
To find age, there are a number of methods, but 

yrdiff(dob,eventdt,'age')

Is probably simlest (assuming you have 9.3 or after version)

To find the record with term=36 then a:

where term=36;

Line can be added to a datastep.

 

For the code presented, no, it is not correct, there are several mistakes in it, no proc sql; / quit; being present is one, a function I do not know as 2, from shouldn't need quotes.

Occasional Contributor
Posts: 9

Re: Calculate Age and filter data

Hi to all,

i have a problem with this:

The dataset initial is below:

ASSET TIPEDOBVEHICLE_AGEVEHICLE COSTREG_DATESNAPSHOT_DATETERM
NEW10/09/8101500001/03/1401/04/1412
USED15/08/8661000001/09/1301/04/1412
NEW26/11/9202000001/03/1401/04/1424
USED17/02/9518500001/09/1201/04/1436

 

 

CAN YOU TELL ME WHAT IS A SAS DATASTEP WHICH CAN BE USED TO FIND THE AGE (IN WHOLE YEARS) FOR THE CUSTOMERS OF THE NEW VEHICLES AS AT SNAPSHOT_DATE.?

AND WHAT IS A SAS DATASTEP CAN BE USED TO FIND THE CONTRACT END DATE OF THE VEHICLE WITH TERM =36, ASSUMING THE VEHICLE WAS PURCHASED ON THE SNAPSHOT_DATE?

 

I THINK THAT THE CORRECT ANSWER IS: 

 

SELECT

ADD_MONTHS(SNAPSHOTDATE,36)

FROM'INITIAL DATA'

WHERE TERM=36

 

CAN YOU HELP ME PLEASE? I HAVE AN IMPORTANT EXAM BUT I DON'T KNOW WHAT IS THE CORRECT ANSWER FOR THIS QUESTION.

Occasional Contributor
Posts: 9

Re: Calculate Age and filter data

 

 

CAN YOU TELL ME WHAT IS A SAS DATASTEP WHICH CAN BE USED TO FIND THE AGE (IN WHOLE YEARS) FOR THE CUSTOMERS OF THE NEW VEHICLES AS AT SNAPSHOT_DATE.?

AND WHAT IS A SAS DATASTEP CAN BE USED TO FIND THE CONTRACT END DATE OF THE VEHICLE WITH TERM =36, ASSUMING THE VEHICLE WAS PURCHASED ON THE SNAPSHOT_DATE?

 

I THINK THAT THE CORRECT ANSWER IS: 

 

SELECT

ADD_MONTHS(SNAPSHOTDATE,36)

FROM'INITIAL DATA'

WHERE TERM=36

 

CAN YOU HELP ME PLEASE? I HAVE AN IMPORTANT EXAM BUT I DON'T KNOW WHAT IS THE CORRECT ANSWER FOR THIS QUESTION.

Super User
Posts: 13,563

Re: Calculate Age and filter data

Since Select as you are showing is not VALID in a DATASTEP, why do you propose that as part of a solution you are requesting for DATASTEP?

 

If your variables are SAS date valued variables with a format such as mmddyy10 then the functions YRDIF or Intck can return "age",

and the function INTNX is used to increment values:

 

data want;

   set have;

   age = intck('year',dob,snapshotdate); /* close by you need to look up more details on your own*/

   contractenddate= intnx('month',snapshotdate,36);

   format contractendate mmddyy10.

run;

 

PLEASE DO NOT SHOUT BY USING ALL CAPITAL LETTERS. AND REPEATING THE EXACT SAME POST IS NOT RESPONDING TO QUESTIONS THAT ARE DESIGNED TO HELP GET A RESPONSE TO YOUR QUESTION.

  

Ask a Question
Discussion stats
  • 6 replies
  • 417 views
  • 0 likes
  • 4 in conversation