BookmarkSubscribeRSS Feed
Fol_
Calcite | Level 5

Hi ,

i have a large dataset that includes a variable which is a record of last date of deposit for clients. So you may have

Client                         Last_dep_date

A                                  27/12/2007

B                                  04/08/2007

C                                  02/04/2008

......with the earliest year being 2007 and the latest year being 2010. (Concentrating on the year only)

The task is to allocate a score based on the YEAR of Last_dep_date. So that a score of 4 is allocated to 2010 and a score of 1 is allocated to 2007 . What statements can i use and how do i compose the query.

Many thanks  

2 REPLIES 2
art297
Opal | Level 21

If last_dep_date is a SAS date, why not just use:

score=year(last_dep_date)-2006;

djbateman
Lapis Lazuli | Level 10

If I understand correctly, you just want to get the year of the Last_dep_date variable?  I would assume that you have the variable stored as a numeric variable with a date format.  If that is the case, then this code will capture just the year:

data

deposit;

input client $ Last_dep_date DDMMYY8.

;

format last_dep-date ddmmyy8.

;

datalines

;

A 27/12/07

B 04/08/07

C 02/04/08

;

run

;

data deposit;

set

deposit;

year=year(last_dep_date);

run

;

If your last_dep_date variable happens to be character, then you can use scan(last_dep_date,3,'/').  This means to treat the date variable as though it is 3 "words" separated by a "/" and you want to keep the 3rd "word" (or the year).

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!

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
  • 2 replies
  • 591 views
  • 0 likes
  • 3 in conversation