BookmarkSubscribeRSS Feed
ARTI1
Calcite | Level 5

Hey All,

I am trying to write a code in SAS where from

Tuesday to Friday, it gets data from previous day (Trans_Date is the variable) and on Monday, I want it to get all three days data from the weekend. Appreciate all the help I get.

 
4 REPLIES 4
Reeza
Super User

WEEKDAY() function tells you what day of the week it is.

ballardw
Super User

First thing is to make sure that you have SAS date valued variables.

Then there are several date related functions that may help.

 

To get specific examples you need to provide data that you have now and what you expect.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

ARTI1
Calcite | Level 5
This is my SQL code that I need to change it to SAS
select * into #switch4 from #TransactionsA where trans_date2>= dateadd(dd, case
substring(datename(dw,getdate()),1,3)
when 'MON'
then -3
else -1 end
,cast(cast(getdate() as date) as datetime))
bobpep212
Quartz | Level 8

Another way to approach this is to maintain a dataset that has a single value...the date it last ran. You then pass that value into a start_date variable that can be used in your program. At the very end, you overwrite the dataset with today's date, that becomes the start date, the next time you run it. This way, if you happen to have a day it can't run during the week, you pick up that data the next day it does run. 

libname mydata "directory_path";
data _null_;
set mydata.last_run_date;
call symputx('start_date',"'"||put(date_last_run,date9.)||"'d");
run;

data want;
set have;
where date_var >= &start_date. and date_var < date();
run;

data mydata.last_run_date;
date_last_run=date();
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 4 replies
  • 639 views
  • 0 likes
  • 4 in conversation