BookmarkSubscribeRSS Feed
alepage
Barite | Level 11

Hello,

 

I don't have any idea how to estimate the various PRV_varname based on the value of date. Negative Lag ?

I have notice that the week start on the Saturday and end on a Friday.

 

Therefore, if the fist January 2025 is Weneday then the begining of the year will be Saturday 28, 2024

Any Way, up to now I was unable to find the logic into these variable

Please don't ask me the purpose of those funzy variables, I don't know.

 

I new to reproduce an existing table but until 2035 without the original SAS code.

 

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Most of us refuse (or cannot) download Excel files, they can be security threats. You need to provide data as SAS data step code, as you have done properly in other threads.

 

I personally assert my rights to ask questions if I feel it is necessary.

--
Paige Miller
Tom
Super User Tom
Super User

I cannot figure out what your question is.

What does "various PRV_varname" mean?  The attached spreadsheet is not very helpful.

 

You mentioned that weeks start on Saturday instead of Sunday.

 

Does that mean you want to calculate week number?

alepage
Barite | Level 11
I have provided the SAS dataset. I would like to estimate all the variables that start by PRV such as PRV_Annee, PRV_Quater, and so on, but I don't understand the logic behind
Patrick
Opal | Level 21

Instead of an xlsx file attached a text file with a SAS data step that creates the data.

 

@alepage 

You will need to provide a bit more detailed explanation for the logic required to calculate these derived date variables. I suggest you focus on only one of these variables and we go from there.

I'd also recommend that you cut-down the sample data to the minimum required to explain the logic and test solutions.

 

Below code provides some example code for use of intnx() with start of year being first Saturday of the year. More info provided already as answer to your earlier question.

/* Therefore, if the fist January 2025 is Weneday then the begining of the year will be Saturday 28, 2024 */
data demo;
	format date weekdatx. sat_start_of_week sat_start_of_year date9.;
	do date='20dec2024'd to '10jan2025'd;
		sat_start_of_week=intnx('week.7',date,0,'b');
		sat_start_of_year=intnx('year', sat_start_of_week, 0, 'b');
		output;
	end;
run;

proc print data=demo;
run;

Patrick_0-1736473611941.png

 

 

alepage
Barite | Level 11

Hello,

 

First thank you very much for you SAS code to get the week start date on a Saturday.

I have kept the same logic for the end of the week.

 

But for the begining of the year, and the end of the year I think values could be different.

 

/* Therefore, if the fist January 2025 is Weneday then the begining of the year will be Saturday 28, 2024 */
data demo;
	format date weekdatx.  sat_start_of_week sat_end_of_week sat_start_of_year sat_end_of_year date9.;
	do date='28dec2013'd to '10jan2015'd;
		sat_start_of_week=intnx('week.7',date,0,'b');
		sat_end_of_week=intnx('week.7',date,0,'e');
		sat_start_of_year=intnx('year', sat_start_of_week, 0, 'b');
		sat_end_of_year=intnx('year', sat_start_of_week, 0, 'e');
		output;
	end;
run;

proc print data=demo;
run;

I am pretty confortable with the estimate for the begining and the end of the week.  It starts on Saturday and end on a Friday.

But if for the week we have a lead of few day should we expect the same for the year ?  So should the year 2014 start on 28dec2013 and end on 02jan2015 ?
So if I want to apply that logic, how do we estimate those two dates?

Ksharp
Super User

You want this ?

 

data _null_;
input date date9.;
want=intnx('week.7',date,0);
put date= date9. want= date9.;
cards;
01jan2025
28jan2025
;

 

17   data _null_;
18   input date date9.;
19   want=intnx('week.7',date,0);
20   put date= date9. want= date9.;
21   cards;

date=01JAN2025 want=28DEC2024
date=28JAN2025 want=25JAN2025
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.01 秒
      CPU 时间          0.00 秒

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 7 replies
  • 1321 views
  • 1 like
  • 5 in conversation