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

Hi guys,

I got stuck with this one assignment, so I was hoping someone could help me out.

Question 1 asks that we must create a table that must consist of the following fields (I have included a description of the fields) :

Field

Description

Format

Key

Unique Key for that Date

Numeric

Date

Date9.

date9.

date_description

Long Description of the date

Character

RSA_WorkdayInd

Whether it is a working day. Assume no public holidays

Numeric

Fin_Year

FNB Financial Year (1Jul - 30 June)

Numeric

WeekendInd

Whether it is a weekend

Numeric

DayOfWeek

The Day of the Week

Character

Calendar_Month

Calendar Month YYYYMM

Numeric

Calendar_Day_of_Month

Day in th Month

Numeric

Calendar_Day_of_Year

Day in the Year

Numeric

Calendar_Week_Number

Week Number in the Year

Numeric

Calendar_Month_Number

Calendar Month Number

Numeric

Calendar_Month_name

Month Name

Character

Calendar_Quarter

Calendar Quarter

Character

Calendar_Year

Calender Year

Numeric

RSA_WorkingTimeMinutes

Assume 8 working hours.

Numeric

In this table you should have every single day from 01Jan2010 – 31 DEC2014 ie you need to generate a record for each day.


I have tried the following, but I'm not sure how to include the months and days, since in the code below it generates the wrong output- can you suggest an easier way to continue with this process ?,


data date_dataset; 

   begin='01JAN2010'd;

   end='31DEC2014'd;

   i=0;

   do year=year(begin) to year(end); 

           do month=month((begin+i)) to month((begin+i+1));

       output;

    end;

    i=i+1;

   end;

run;


Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Hi

Have a look at this sample code, it should give you a starting point. There are several functions that return information from a date like DAY, YEAR, MONTH, QTR etc. You can also use the PUT function together with a date format to get your char values

%let fromDate = 01Jan2010;
%let toDate = 31DEC2014;
data want;
  length key 8;
 
do date = "&fromDate"d to "&toDate"d;
    key +
1;
    RSA_WorkdayInd = (
2 <= weekday(date) <= 6);
    WeekendInd = (not RSA_WorkdayInd);
    Calendar_Week_Number = week(date,
"V");
    DayOfWeek = put(date, downame3.);
    Fin_Year = year(intnx("year.7", date, 0));
    output;
 
end;

 
format
    date
date9.
  ;
run;

View solution in original post

3 REPLIES 3
BrunoMueller
SAS Super FREQ

Hi

Have a look at this sample code, it should give you a starting point. There are several functions that return information from a date like DAY, YEAR, MONTH, QTR etc. You can also use the PUT function together with a date format to get your char values

%let fromDate = 01Jan2010;
%let toDate = 31DEC2014;
data want;
  length key 8;
 
do date = "&fromDate"d to "&toDate"d;
    key +
1;
    RSA_WorkdayInd = (
2 <= weekday(date) <= 6);
    WeekendInd = (not RSA_WorkdayInd);
    Calendar_Week_Number = week(date,
"V");
    DayOfWeek = put(date, downame3.);
    Fin_Year = year(intnx("year.7", date, 0));
    output;
 
end;

 
format
    date
date9.
  ;
run;
mjheever
Obsidian | Level 7

Thank you Bruno.

I will try this code out and also apply a similar approach to the rest of the fields.

I will give an update on the result once I've applied it to all the fields.

mjheever
Obsidian | Level 7

OutputBruno.jpg

Here is the output Bruno- it worked like a charm.

Thank you once again :smileygrin: :smileygrin: :smileygrin: :smileygrin:  :smileygrin: !

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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