BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jspoend
Obsidian | Level 7

Hi there, 

 

I have a dataset with 1 line per ID with one relevant date per ID.

I have transformed the dates into numeric format using 'date_as_num = putn(date,'yymmddn8.');'. 

The date range is 1 January 2018 (i.e. 20180101) to 31 December 2020 (20201231). 

I now need to convert these dates into consecutive numbers starting at 1 with 1 January 2018 being 1, 2 January being 2 and so forth. 

 

I'm using SAS version 9.4. 

 

I don't know how to do this. Can anyone help? 

 

Thank you very much! 

 

Julia

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
The variable DATE is already on a sliding scale, increasing by 1 every day. To change the scale so it starts at 1 on January 1, 2018, use:

data want;
set have;
sliding_scale = date - '31dec2017'd;;
run;

I would recommend studying up on how SAS handles dates. Time well spent.

View solution in original post

2 REPLIES 2
Astounding
PROC Star
The variable DATE is already on a sliding scale, increasing by 1 every day. To change the scale so it starts at 1 on January 1, 2018, use:

data want;
set have;
sliding_scale = date - '31dec2017'd;;
run;

I would recommend studying up on how SAS handles dates. Time well spent.
jspoend
Obsidian | Level 7

Thank you so much, this worked well. 

 

I totally agree, that understanding dates in SAS is worthwhile. I

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 500 views
  • 1 like
  • 2 in conversation