Hi,
I'm trying to find the Week Begin Date from a Given Date with Saturday as the Starting point. I've tried the following code but it always yields a Sunday Start Date. I would like x=24Oct2019 to return 10/20/19 (Saturday) & 26Oct2019 to return 10/26/19 (Also Saturday).
data _null_;
x='24Oct2019'd;
e=intnx("week",x,0,"B")
put e=;
format e mmddyy10;
run;
Thanks
data _null_;
do x='20Oct2019'd to '30Oct2019'd;
e=intnx("week.7",x,0,"B");
put (x e) (+1 yymmdd10.);
end;
run;
2019-10-20 2019-10-19 2019-10-21 2019-10-19 2019-10-22 2019-10-19 2019-10-23 2019-10-19 2019-10-24 2019-10-19 2019-10-25 2019-10-19 2019-10-26 2019-10-26 2019-10-27 2019-10-26 2019-10-28 2019-10-26 2019-10-29 2019-10-26 2019-10-30 2019-10-26
Thanks. Worked Perfectly.
@PGStats wrote:
data _null_; do x='20Oct2019'd to '30Oct2019'd; e=intnx("week.7",x,0,"B"); put (x e) (+1 yymmdd10.); end; run;
2019-10-20 2019-10-19 2019-10-21 2019-10-19 2019-10-22 2019-10-19 2019-10-23 2019-10-19 2019-10-24 2019-10-19 2019-10-25 2019-10-19 2019-10-26 2019-10-26 2019-10-27 2019-10-26 2019-10-28 2019-10-26 2019-10-29 2019-10-26 2019-10-30 2019-10-26
Hi @PGStats ,
Just a curiosity question. What does this line do?
put (x e) (+1 yymmdd10.);
I know that put will conver num to char, but I don't understand the "+1"?
The +1 adds a space character. Try removing it!
@PGStats wrote:
The +1 adds a space character. Try removing it!
I'll for sure. There's so many "behind the scene" tricks with SAS that I don't know. I didn't know that you can use put (var1 var2) (format) in that way.
Thanks for your help.
e=intnx("week.7",x,0,"B")
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.